mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[openwebnet] add date time synchronization feature for bus_gateway Things (#15115)
* [openwebnet] fist commit DateTime synch --------- Signed-off-by: Massimo Valla <mvcode00@gmail.com>
This commit is contained in:
parent
59ebd37a88
commit
3e0099d6d1
@ -107,6 +107,7 @@ Configuration parameters are:
|
||||
- if the BUS/SCS gateway is configured to accept connections from the openHAB computer IP address, no password should be required
|
||||
- in all other cases, a password must be configured. This includes gateways that have been discovered and added from Inbox: without a password configured they will remain OFFLINE
|
||||
- `discoveryByActivation`: discover BUS devices when they are activated also when a device scan hasn't been started from Inbox (`boolean`, _optional_, default: `false`). See [Discovery by Activation](#discovery-by-activation).
|
||||
- `dateTimeSynch`: synchronise date and time of slave elements on the SCS BUS using openHAB timestamp (`boolean`, _optional_, default: `false`). Set this parameter to `true` to send time-date synchronisation commands on the BUS when the timestamp received from the gateway differs by more than 1 minute from that of openHAB. Useful if the BUS gateway is not syncronized with Internet time servers and with daylight saving time changes.
|
||||
|
||||
Alternatively the BUS/SCS Gateway thing can be configured using the `.things` file, see `openwebnet.things` example [below](#full-example).
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>io.github.openwebnet4j</groupId>
|
||||
<artifactId>openwebnet4j</artifactId>
|
||||
<version>0.9.1</version>
|
||||
<version>0.10.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -14,6 +14,8 @@ package org.openhab.binding.openwebnet.internal.handler;
|
||||
|
||||
import static org.openhab.binding.openwebnet.internal.OpenWebNetBindingConstants.*;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -91,6 +93,8 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
|
||||
private static final int REFRESH_ALL_CHECK_DELAY_SEC = 20; // Delay to wait to check which devices are
|
||||
// online/offline
|
||||
|
||||
private static final int DATETIME_SYNCH_DIFF_SEC = 60; // Difference from BUS date time
|
||||
|
||||
private long lastRegisteredDeviceTS = -1; // timestamp when the last device has been associated to the bridge
|
||||
private long refreshAllDevicesDelay = 0; // delay waited before starting all devices refresh
|
||||
|
||||
@ -114,6 +118,7 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
|
||||
|
||||
private boolean scanIsActive = false; // a device scan has been activated by OpenWebNetDeviceDiscoveryService;
|
||||
private boolean discoveryByActivation;
|
||||
private boolean dateTimeSynch = false;
|
||||
|
||||
public OpenWebNetBridgeHandler(Bridge bridge) {
|
||||
super(bridge);
|
||||
@ -201,8 +206,10 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
|
||||
passwdMasked = "******";
|
||||
}
|
||||
discoveryByActivation = busBridgeConfig.getDiscoveryByActivation();
|
||||
logger.debug("Creating new BUS gateway with config properties: {}:{}, pwd={}, discoveryByActivation={}",
|
||||
host, port, passwdMasked, discoveryByActivation);
|
||||
dateTimeSynch = busBridgeConfig.getDateTimeSynch();
|
||||
logger.debug(
|
||||
"Creating new BUS gateway with config properties: {}:{}, pwd={}, discoveryByActivation={}, dateTimeSynch={}",
|
||||
host, port, passwdMasked, discoveryByActivation, dateTimeSynch);
|
||||
return new BUSGateway(host, port, passwd);
|
||||
}
|
||||
}
|
||||
@ -499,7 +506,10 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
|
||||
}
|
||||
// GATEWAY MANAGEMENT
|
||||
if (msg instanceof GatewayMgmt) {
|
||||
// noop
|
||||
GatewayMgmt gwMsg = (GatewayMgmt) msg;
|
||||
if (dateTimeSynch && GatewayMgmt.DimGatewayMgmt.DATETIME.equals(gwMsg.getDim())) {
|
||||
checkDateTimeDiff(gwMsg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@ -528,6 +538,31 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDateTimeDiff(GatewayMgmt gwMsg) {
|
||||
try {
|
||||
ZonedDateTime now = ZonedDateTime.now();
|
||||
ZonedDateTime gwTime = GatewayMgmt.parseDateTime(gwMsg);
|
||||
long diff = Math.abs(Duration.between(now, gwTime).toSeconds());
|
||||
if (diff > DATETIME_SYNCH_DIFF_SEC) {
|
||||
logger.debug("checkDateTimeDiff: difference is more than 60s: {}s", diff);
|
||||
OpenGateway gw = gateway;
|
||||
if (gw != null) {
|
||||
logger.debug("checkDateTimeDiff: synch DateTime to: {}", now);
|
||||
try {
|
||||
gw.send(GatewayMgmt.requestSetDateTime(now));
|
||||
} catch (OWNException e) {
|
||||
logger.warn("checkDateTimeDiff: Exception while sending set DateTime command: {}",
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.debug("checkDateTimeDiff: DateTime difference: {}s", diff);
|
||||
}
|
||||
} catch (FrameException e) {
|
||||
logger.warn("checkDateTimeDiff: FrameException while parsing {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected() {
|
||||
isGatewayConnected = true;
|
||||
|
@ -30,6 +30,7 @@ public class OpenWebNetBusBridgeConfig {
|
||||
private @Nullable String host;
|
||||
private String passwd = "12345";
|
||||
private boolean discoveryByActivation = false;
|
||||
private boolean dateTimeSynch = false;
|
||||
|
||||
public BigDecimal getPort() {
|
||||
return port;
|
||||
@ -46,4 +47,8 @@ public class OpenWebNetBusBridgeConfig {
|
||||
public Boolean getDiscoveryByActivation() {
|
||||
return discoveryByActivation;
|
||||
}
|
||||
|
||||
public Boolean getDateTimeSynch() {
|
||||
return dateTimeSynch;
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,8 @@ thing-type.config.openwebnet.bus_dry_contact_ir.where.label = OpenWebNet Address
|
||||
thing-type.config.openwebnet.bus_dry_contact_ir.where.description = Automation Dry Contacts (N=1-201): example N=60 --> where=360. Alarm Dry Contacts and IR sensors (Zone=1-9, N=1-9): example Zone=4, N=5 --> where=345
|
||||
thing-type.config.openwebnet.bus_energy_meter.where.label = OpenWebNet Address (where)
|
||||
thing-type.config.openwebnet.bus_energy_meter.where.description = Example: 5N with N=[1-255]
|
||||
thing-type.config.openwebnet.bus_gateway.dateTimeSynch.label = Date Time Synchronisation
|
||||
thing-type.config.openwebnet.bus_gateway.dateTimeSynch.description = Synchronise date and time of slave elements on the SCS BUS using openHAB timestamp (default: false)
|
||||
thing-type.config.openwebnet.bus_gateway.discoveryByActivation.label = Discovery By Activation
|
||||
thing-type.config.openwebnet.bus_gateway.discoveryByActivation.description = Discover BUS devices when they are activated (also when a device scan is not active) (default: false)
|
||||
thing-type.config.openwebnet.bus_gateway.host.label = Host
|
||||
|
@ -45,6 +45,12 @@
|
||||
<default>false</default>
|
||||
</parameter>
|
||||
|
||||
<parameter name="dateTimeSynch" type="boolean">
|
||||
<label>Date Time Synchronisation</label>
|
||||
<description>Synchronise date and time of slave elements on the SCS BUS using openHAB timestamp (default: false)</description>
|
||||
<default>false</default>
|
||||
</parameter>
|
||||
|
||||
</config-description>
|
||||
|
||||
</bridge-type>
|
||||
|
Loading…
Reference in New Issue
Block a user