]> git.basschouten.com Git - openhab-addons.git/commitdiff
[openwebnet] fixed generic device thing-type; added a time limit to devices refresh...
authorM Valla <12682715+mvalla@users.noreply.github.com>
Sun, 20 Mar 2022 08:53:50 +0000 (09:53 +0100)
committerGitHub <noreply@github.com>
Sun, 20 Mar 2022 08:53:50 +0000 (09:53 +0100)
Signed-off-by: Massimo Valla <mvcode00@gmail.com>
bundles/org.openhab.binding.openwebnet/README.md
bundles/org.openhab.binding.openwebnet/src/main/java/org/openhab/binding/openwebnet/internal/handler/OpenWebNetBridgeHandler.java
bundles/org.openhab.binding.openwebnet/src/main/resources/OH-INF/thing/GenericDevice.xml

index 043cfdb30f8a11d586d4512427d06d1d233b57bb..bbccb32565c2e65a3daa5dc9c7dc794e94c99d8e 100644 (file)
@@ -234,7 +234,8 @@ See [openwebnet.sitemap](#openwebnet-sitemap) & [openwebnet.rules](#openwebnet-r
 
 There are three WEEKLY and sixteen SCENARIO programs defined for the Central Unit.
 
-In order to activate one of them you have to use two different channels: 
+In order to activate one of them you have to use two different channels:
+
 - with `mode` you can set the mode (`WEEKLY` or `SCENARIO`)
 - with `weeklyProgram` (if `WEEKLY` was setted) or with `scenarioProgram` (if `SCENARIO` was setted) you can set the program number
 
index e0b06291627c5a9bd58339115469cbb1cb2a925d..f28de749ab064331f15b84c40e52f64a335f344f 100644 (file)
@@ -78,11 +78,16 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
 
     private static final int GATEWAY_ONLINE_TIMEOUT_SEC = 20; // Time to wait for the gateway to become connected
 
-    private static final int REFRESH_ALL_DEVICES_DELAY_MSEC = 500; // Delay to wait before sending all devices refresh
-                                                                   // request after a connect/reconnect
-    private static final int REFRESH_ALL_CHECK_DELAY_SEC = 20;
+    private static final int REFRESH_ALL_DEVICES_DELAY_MSEC = 500; // Delay to wait before trying again another all
+                                                                   // devices refresh request after a connect/reconnect
+    private static final int REFRESH_ALL_DEVICES_DELAY_MAX_MSEC = 15000; // Maximum delay to wait for all devices
+                                                                         // refresh after a connect/reconnect
 
-    private static long lastRegisteredDeviceTS = -1; // timestamp when the last device has been associated to the bridge
+    private static final int REFRESH_ALL_CHECK_DELAY_SEC = 20; // Delay to wait to check which devices are
+                                                               // online/offline
+
+    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
 
     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.BRIDGE_SUPPORTED_THING_TYPES;
 
@@ -410,32 +415,43 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
         int total = things.size();
         logger.debug("--- FOUND {} things by getThings()", total);
         if (total > 0) {
-            if (registeredDevices.isEmpty()
-                    || (System.currentTimeMillis() - lastRegisteredDeviceTS < REFRESH_ALL_DEVICES_DELAY_MSEC)) {
-                // if a device has been registered with the bridge just now, let's wait for other devices: re-schedule
+            if (registeredDevices.isEmpty()) { // no registered device yet
+                if (refreshAllDevicesDelay < REFRESH_ALL_DEVICES_DELAY_MAX_MSEC) {
+                    logger.debug("--- REGISTER device not started yet... re-scheduling refreshAllBridgeDevices()");
+                    refreshAllDevicesDelay += REFRESH_ALL_DEVICES_DELAY_MSEC * 3;
+                    refreshAllSchedule = scheduler.schedule(this::refreshAllBridgeDevices,
+                            REFRESH_ALL_DEVICES_DELAY_MSEC * 3, TimeUnit.MILLISECONDS);
+                    return;
+                } else {
+                    logger.warn(
+                            "--- --- NONE OF {} CHILD DEVICE(S) has REGISTERED with bridge {}: check Things configuration (stopping refreshAllBridgeDevices)",
+                            total, thing.getUID());
+                    refreshAllDevicesDelay = 0;
+                    return;
+                }
+            } else if (System.currentTimeMillis() - lastRegisteredDeviceTS < REFRESH_ALL_DEVICES_DELAY_MSEC) {
+                // a device has been registered with the bridge just now, let's wait for other devices: re-schedule
                 // refreshAllDevices
-                logger.debug(
-                        "--- REGISTER device not started or just called... re-scheduling refreshAllBridgeDevices()");
+                logger.debug("--- REGISTER device just called... re-scheduling refreshAllBridgeDevices()");
                 refreshAllSchedule = scheduler.schedule(this::refreshAllBridgeDevices, REFRESH_ALL_DEVICES_DELAY_MSEC,
                         TimeUnit.MILLISECONDS);
-            } else {
-                for (Thing ownThing : things) {
-                    OpenWebNetThingHandler hndlr = (OpenWebNetThingHandler) ownThing.getHandler();
-                    if (hndlr != null) {
-                        howMany++;
-                        logger.debug("--- REFRESHING ALL DEVICES FOR thing #{}/{}: {}", howMany, total,
-                                ownThing.getUID());
-                        hndlr.refreshAllDevices();
-                    } else {
-                        logger.warn("--- No handler for thing {}", ownThing.getUID());
-                    }
+                return;
+            }
+            for (Thing ownThing : things) {
+                OpenWebNetThingHandler hndlr = (OpenWebNetThingHandler) ownThing.getHandler();
+                if (hndlr != null) {
+                    howMany++;
+                    logger.debug("--- REFRESHING ALL DEVICES FOR thing #{}/{}: {}", howMany, total, ownThing.getUID());
+                    hndlr.refreshAllDevices();
+                } else {
+                    logger.warn("--- No handler for thing {}", ownThing.getUID());
                 }
-                logger.debug("--- --- COMPLETED REFRESH all devices for bridge {}", thing.getUID());
-
-                // set a check that all things are Online
-                refreshAllSchedule = scheduler.schedule(() -> checkAllRefreshed(things), REFRESH_ALL_CHECK_DELAY_SEC,
-                        TimeUnit.SECONDS);
             }
+            logger.debug("--- --- COMPLETED REFRESH all devices for bridge {}", thing.getUID());
+            refreshAllDevicesDelay = 0;
+            // set a check that all things are Online
+            refreshAllSchedule = scheduler.schedule(() -> checkAllRefreshed(things), REFRESH_ALL_CHECK_DELAY_SEC,
+                    TimeUnit.SECONDS);
         } else {
             logger.debug("--- --- NO CHILD DEVICE to REFRESH for bridge {}", thing.getUID());
         }
index 0cbfbce668cf8bf6926ceeab86ab4a381e6be6fa..830ee0e59ff79cfd49f6faf07f4ba872960ada05 100644 (file)
@@ -5,7 +5,7 @@
        xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">
 
        <!-- OpenWebNet Generic Device -->
-       <thing-type id="device">
+       <thing-type id="generic_device">
                <supported-bridge-type-refs>
                        <bridge-type-ref id="bus_gateway"/>
                        <bridge-type-ref id="zb_gateway"/>