]> git.basschouten.com Git - openhab-addons.git/commitdiff
[insteon] set device offline if it doesn't exist in the plm/hub database (#12904)
authorrobnielsen <rob.nielsen@yahoo.com>
Tue, 14 Jun 2022 21:26:08 +0000 (16:26 -0500)
committerGitHub <noreply@github.com>
Tue, 14 Jun 2022 21:26:08 +0000 (23:26 +0200)
* [insteon] set device offline if it doesn't exist in the plm/hub database
* [insteon] use a flag to indicate if a device is linked or not
* [insteon] set config to @NonNullByDefault({}) instead of @Nullable
* [insteon] cleanup

Signed-off-by: Rob Nielsen <rob.nielsen@yahoo.com>
bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/InsteonBinding.java
bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonDeviceHandler.java
bundles/org.openhab.binding.insteon/src/main/java/org/openhab/binding/insteon/internal/handler/InsteonNetworkHandler.java

index bafc5f0edee40ec9898ec84b66b1d36bb2ca2198..fa21489efeb476aeb9225d3110ed8cdaa3a81777 100644 (file)
@@ -320,6 +320,7 @@ public class InsteonBinding {
             } else {
                 if (driver.isModemDBComplete() && !addr.isX10()) {
                     logger.warn("device {} not found in the modem database. Did you forget to link?", addr);
+                    handler.deviceNotLinked(addr);
                 }
             }
             return dbes.size();
@@ -488,6 +489,7 @@ public class InsteonBinding {
                     if (!dbes.containsKey(a)) {
                         if (!a.isX10()) {
                             logger.warn("device {} not found in the modem database. Did you forget to link?", a);
+                            handler.deviceNotLinked(a);
                         }
                     } else {
                         if (!dev.hasModemDBEntry()) {
index 14d7db070e800fda507b444f4625fecf6f919cc3..4c2bf66e3b944122bd7580752d88fa4191e20802 100644 (file)
@@ -26,7 +26,6 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.insteon.internal.InsteonBinding;
 import org.openhab.binding.insteon.internal.InsteonBindingConstants;
 import org.openhab.binding.insteon.internal.config.InsteonChannelConfiguration;
@@ -125,7 +124,8 @@ public class InsteonDeviceHandler extends BaseThingHandler {
 
     private final Logger logger = LoggerFactory.getLogger(InsteonDeviceHandler.class);
 
-    private @Nullable InsteonDeviceConfiguration config;
+    private @NonNullByDefault({}) InsteonDeviceConfiguration config;
+    private boolean deviceLinked = true;
 
     public InsteonDeviceHandler(Thing thing) {
         super(thing);
@@ -134,6 +134,7 @@ public class InsteonDeviceHandler extends BaseThingHandler {
     @Override
     public void initialize() {
         config = getConfigAs(InsteonDeviceConfiguration.class);
+        deviceLinked = true;
 
         scheduler.execute(() -> {
             final Bridge bridge = getBridge();
@@ -373,7 +374,9 @@ public class InsteonDeviceHandler extends BaseThingHandler {
                 });
 
                 if (ThingStatus.ONLINE == bridge.getStatus()) {
-                    updateStatus(ThingStatus.ONLINE);
+                    if (deviceLinked) {
+                        updateStatus(ThingStatus.ONLINE);
+                    }
                 } else {
                     updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
                 }
@@ -533,6 +536,18 @@ public class InsteonDeviceHandler extends BaseThingHandler {
         logger.debug("channel {} unlinked ", channelUID.getAsString());
     }
 
+    public InsteonAddress getInsteonAddress() {
+        return new InsteonAddress(config.getAddress());
+    }
+
+    public void deviceNotLinked() {
+        String msg = "device with the address '" + config.getAddress()
+                + "' was not found in the modem database. Did you forget to link?";
+        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, msg);
+
+        deviceLinked = false;
+    }
+
     private InsteonNetworkHandler getInsteonNetworkHandler() {
         Bridge bridge = getBridge();
         if (bridge == null) {
index c803e88d82b1e9009ab0287bc1417fe55f4277df..56ef95c93e456ee6a4bba2a44d63c466123c30f2 100644 (file)
@@ -23,6 +23,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.openhab.binding.insteon.internal.InsteonBinding;
 import org.openhab.binding.insteon.internal.config.InsteonNetworkConfiguration;
+import org.openhab.binding.insteon.internal.device.InsteonAddress;
 import org.openhab.binding.insteon.internal.discovery.InsteonDeviceDiscoveryService;
 import org.openhab.core.io.console.Console;
 import org.openhab.core.io.transport.serial.SerialPortManager;
@@ -205,6 +206,16 @@ public class InsteonNetworkHandler extends BaseBridgeHandler {
         });
     }
 
+    public void deviceNotLinked(InsteonAddress addr) {
+        getThing().getThings().stream().forEach((thing) -> {
+            InsteonDeviceHandler handler = (InsteonDeviceHandler) thing.getHandler();
+            if (handler != null && addr.equals(handler.getInsteonAddress())) {
+                handler.deviceNotLinked();
+                return;
+            }
+        });
+    }
+
     public void displayDevices(Console console) {
         display(console, deviceInfo);
     }