From e32a262c308d564e330d2921d6e8359139d37665 Mon Sep 17 00:00:00 2001 From: M Valla <12682715+mvalla@users.noreply.github.com> Date: Mon, 5 Oct 2020 17:50:38 +0200 Subject: [PATCH] [openwebnet] Fixes #8524 and #8547, updated openwebnet4j lib to 0.3.1. Updated README (#8645) Signed-off-by: Massimo Valla --- .../org.openhab.binding.openwebnet/README.md | 5 +++-- .../org.openhab.binding.openwebnet/pom.xml | 2 +- .../handler/OpenWebNetBridgeHandler.java | 20 ++++++++++++++----- .../OpenWebNetDeviceDiscoveryService.java | 11 +++++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.openwebnet/README.md b/bundles/org.openhab.binding.openwebnet/README.md index bac537abb0c..32c56977c23 100644 --- a/bundles/org.openhab.binding.openwebnet/README.md +++ b/bundles/org.openhab.binding.openwebnet/README.md @@ -66,7 +66,7 @@ For other gateways you can add them manually, see [Thing Configuration](#thing-c Devices can also be discovered if activated while an Inbox Scan is active: start a new Scan, wait 15-20 seconds and then _while the Scan is still active_ (spinning arrow in Inbox), activate the physical device (for example dim the dimmer) to have it discovered by the binding. -If a device cannot be discovered automatically it's always possible to add them manually, see [Configuring Devices](#configuring-devices). +If a device cannot be discovered automatically it's always possible to add it manually, see [Configuring Devices](#configuring-devices). ### ZigBee Discovery @@ -210,5 +210,6 @@ Special thanks for helping on testing this binding go to: [@k0nti](https://community.openhab.org/u/k0nti/), [@gilberto.cocchi](https://community.openhab.org/u/gilberto.cocchi/), [@llegovich](https://community.openhab.org/u/llegovich), -[@gabriele.daltoe](https://community.openhab.org/u/gabriele.daltoe) +[@gabriele.daltoe](https://community.openhab.org/u/gabriele.daltoe), +[@feodor](https://community.openhab.org/u/feodor) and many others at the fantastic openHAB community! diff --git a/bundles/org.openhab.binding.openwebnet/pom.xml b/bundles/org.openhab.binding.openwebnet/pom.xml index dfb16029d68..a779114839d 100644 --- a/bundles/org.openhab.binding.openwebnet/pom.xml +++ b/bundles/org.openhab.binding.openwebnet/pom.xml @@ -23,7 +23,7 @@ com.github.openwebnet4j openwebnet4j - 0.3.0 + 0.3.1 compile diff --git a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/handler/OpenWebNetBridgeHandler.java b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/handler/OpenWebNetBridgeHandler.java index b917aca2ae8..451ad9473ce 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/handler/OpenWebNetBridgeHandler.java +++ b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/handler/OpenWebNetBridgeHandler.java @@ -314,16 +314,26 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement /** * Un-register a device from this bridge handler * - * @param oId the device OpenWebNet id + * @param ownId the device OpenWebNet id */ - protected void unregisterDevice(String oId) { - if (registeredDevices.remove(oId) != null) { - logger.debug("un-registered device ownId={}", oId); + protected void unregisterDevice(String ownId) { + if (registeredDevices.remove(ownId) != null) { + logger.debug("un-registered device ownId={}", ownId); } else { - logger.warn("could not un-register ownId={} (not found)", oId); + logger.warn("could not un-register ownId={} (not found)", ownId); } } + /** + * Get an already registered device on this bridge handler + * + * @param ownId the device OpenWebNet id + * @return the registered device Thing handler or null if the id cannot be found + */ + public @Nullable OpenWebNetThingHandler getRegisteredDevice(String ownId) { + return registeredDevices.get(ownId); + } + @Override public void onEventMessage(@Nullable OpenMessage msg) { logger.trace("RECEIVED <<<<< {}", msg); diff --git a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java index 60bb8535042..3668722bdae 100644 --- a/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java +++ b/bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/discovery/OpenWebNetDeviceDiscoveryService.java @@ -138,6 +138,15 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService deviceWho = baseMsg.getWho(); } } + + String ownId = bridgeHandler.ownIdFromWhoWhere(where, deviceWho); + if (thingTypeUID == OpenWebNetBindingConstants.THING_TYPE_BUS_ON_OFF_SWITCH) { + if (bridgeHandler.getRegisteredDevice(ownId) != null) { + logger.debug("dimmer/switch with WHERE={} already registered, skipping this discovery result", where); + return; + } + } + String tId = bridgeHandler.thingIdFromWhere(where); ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, tId); @@ -159,7 +168,7 @@ public class OpenWebNetDeviceDiscoveryService extends AbstractDiscoveryService } Map properties = new HashMap<>(2); properties.put(OpenWebNetBindingConstants.CONFIG_PROPERTY_WHERE, bridgeHandler.normalizeWhere(where)); - properties.put(OpenWebNetBindingConstants.PROPERTY_OWNID, bridgeHandler.ownIdFromWhoWhere(where, deviceWho)); + properties.put(OpenWebNetBindingConstants.PROPERTY_OWNID, ownId); if (thingTypeUID == OpenWebNetBindingConstants.THING_TYPE_GENERIC_DEVICE) { thingLabel = thingLabel + " (WHO=" + deviceWho + ", WHERE=" + whereLabel + ")"; } else {