mirror of
https://github.com/danieldemus/openhab-addons
synced 2026-07-29 12:34:21 +02:00
[lgtvserial] Make refresh interval configurable (#18559)
Signed-off-by: Hans Böhm <h.boehm@gmx.at>
This commit is contained in:
@@ -43,10 +43,11 @@ No discovery supported; manual configuration is required.
|
||||
|
||||
The thing has the following configuration parameters:
|
||||
|
||||
| Parameter Label | Parameter ID | Description | Accepted values |
|
||||
|------------------------|----------------------|---------------------------------------------------------------------------------|------------------|
|
||||
| Serial Port | port | Serial port to use for connecting to TV/monitor/projector. | Serial port name |
|
||||
| Set ID | setId | Set ID configured in the TV. If 0, will send the commands to every chained TV. | 0-99; default 1 |
|
||||
| Parameter Label | Parameter ID | Description | Accepted values |
|
||||
|------------------------|----------------------|---------------------------------------------------------------------------------|-----------------------|
|
||||
| Serial Port | port | Serial port to use for connecting to TV/monitor/projector. | Serial port name |
|
||||
| Refresh Interval | refreshInterval | Interval at which updates are pulled from the TV (in seconds). | 10-65535; default 120 |
|
||||
| Set ID | setId | Set ID configured in the TV. If 0, will send the commands to every chained TV. | 0-99; default 1 |
|
||||
|
||||
It is necessary to specify the serial port used for communication.
|
||||
On Linux systems, this will usually be either `/dev/ttyS0`, `/dev/ttyUSB0` or `/dev/ttyACM0` (or a higher number than `0` if multiple devices are present).
|
||||
|
||||
+8
-4
@@ -26,6 +26,7 @@ import org.openhab.binding.lgtvserial.internal.protocol.serial.LGSerialResponse;
|
||||
import org.openhab.binding.lgtvserial.internal.protocol.serial.LGSerialResponseListener;
|
||||
import org.openhab.binding.lgtvserial.internal.protocol.serial.SerialCommunicatorFactory;
|
||||
import org.openhab.binding.lgtvserial.internal.protocol.serial.commands.CommandFactory;
|
||||
import org.openhab.core.config.core.Configuration;
|
||||
import org.openhab.core.io.transport.serial.PortInUseException;
|
||||
import org.openhab.core.io.transport.serial.SerialPortIdentifier;
|
||||
import org.openhab.core.io.transport.serial.SerialPortManager;
|
||||
@@ -53,7 +54,7 @@ public class LgTvSerialHandler extends BaseThingHandler {
|
||||
/**
|
||||
* Interval at which to send update refresh commands.
|
||||
*/
|
||||
private static final int EVENT_REFRESH_INTERVAL = 120;
|
||||
private static final int DEFAULT_REFRESH_INTERVAL_SEC = 120;
|
||||
|
||||
/**
|
||||
* Logger.
|
||||
@@ -104,8 +105,10 @@ public class LgTvSerialHandler extends BaseThingHandler {
|
||||
|
||||
@Override
|
||||
public synchronized void initialize() {
|
||||
String portName = (String) getThing().getConfiguration().get("port");
|
||||
BigDecimal setIdParam = (BigDecimal) getThing().getConfiguration().get("setId");
|
||||
Configuration config = getThing().getConfiguration();
|
||||
String portName = (String) config.get("port");
|
||||
int refreshInterval = ((BigDecimal) config.get("refreshInterval")).intValue();
|
||||
BigDecimal setIdParam = (BigDecimal) config.get("setId");
|
||||
int setId = 1;
|
||||
if (setIdParam != null) {
|
||||
setId = setIdParam.intValue();
|
||||
@@ -168,7 +171,8 @@ public class LgTvSerialHandler extends BaseThingHandler {
|
||||
}
|
||||
|
||||
if (updateJob == null || updateJob.isCancelled()) {
|
||||
updateJob = scheduler.scheduleWithFixedDelay(eventRunnable, 0, EVENT_REFRESH_INTERVAL, TimeUnit.SECONDS);
|
||||
updateJob = scheduler.scheduleWithFixedDelay(eventRunnable, 0,
|
||||
refreshInterval > 0 ? refreshInterval : DEFAULT_REFRESH_INTERVAL_SEC, TimeUnit.SECONDS);
|
||||
}
|
||||
// trigger REFRESH commands for all linked Channels to start polling
|
||||
getThing().getChannels().forEach(channel -> {
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
<label>Serial Port</label>
|
||||
<description>Select serial port (COM1, /dev/ttyS0, ...)</description>
|
||||
</parameter>
|
||||
<parameter name="refreshInterval" type="integer" max="65535" min="10" unit="s" required="false">
|
||||
<label>Refresh Interval</label>
|
||||
<description>Refresh interval in seconds</description>
|
||||
<default>120</default>
|
||||
<advanced>true</advanced>
|
||||
</parameter>
|
||||
<parameter name="setId" type="integer" required="true">
|
||||
<label>Set ID</label>
|
||||
<description>Set ID configured in the TV. If 0, will send the commands to every chained TV.</description>
|
||||
|
||||
+2
@@ -22,6 +22,8 @@ thing-type.lgtvserial.lgtv.description = Generic LG television connected through
|
||||
|
||||
thing-type.config.lgtvserial.serial.port.label = Serial Port
|
||||
thing-type.config.lgtvserial.serial.port.description = Select serial port (COM1, /dev/ttyS0, ...)
|
||||
thing-type.config.lgtvserial.serial.refreshInterval.label = Refresh Interval
|
||||
thing-type.config.lgtvserial.serial.refreshInterval.description = Refresh interval in seconds
|
||||
thing-type.config.lgtvserial.serial.setId.label = Set ID
|
||||
thing-type.config.lgtvserial.serial.setId.description = Set ID configured in the TV. If 0, will send the commands to every chained TV.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user