]> git.basschouten.com Git - openhab-addons.git/commitdiff
[Hydrawise] concurrent error (#13268)
authorDan Cunningham <dan@digitaldan.com>
Wed, 17 Aug 2022 08:07:04 +0000 (01:07 -0700)
committerGitHub <noreply@github.com>
Wed, 17 Aug 2022 08:07:04 +0000 (10:07 +0200)
* Fixes a concurrent modification exception, cleans up handler on dispose, fixes totally broken last contact channel
Fixes #13094

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
bundles/org.openhab.binding.hydrawise/README.md
bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/handler/HydrawiseAccountHandler.java
bundles/org.openhab.binding.hydrawise/src/main/java/org/openhab/binding/hydrawise/internal/handler/HydrawiseControllerHandler.java
bundles/org.openhab.binding.hydrawise/src/main/resources/OH-INF/thing/channel-types.xml

index 33df7cb438367ee1338ceaeb869917a63e7ac8e3..2d9d17e76818e476d8cf15eaf7c4cf5f28ac5f7d 100644 (file)
@@ -172,7 +172,7 @@ Group SprinklerSensors      "Sensors"       (Sprinkler)
 Group SprinkerForecast      "Forecast"      (Sprinkler)
 
 String SprinkerControllerStatus "Status [%s]" (SprinklerController) {channel="hydrawise:controller:myaccount:123456:controller#status"}
-Number SprinkerControllerLastContact "Last Contact [%d]" (SprinklerController) {channel="hydrawise:controller:myaccount:123456:controller#lastContact"}
+Number SprinkerControllerLastContact "Last Contact [%d]" (SprinklerController) {channel="hydrawise:controller:myaccount:123456:controller#lastcontact"}
 
 Switch SprinklerSensor1 "Sprinler Sensor" (SprinklerSensors) {channel="hydrawise:controller:myaccount:123456:sensor1#active"}
 
index 8aca2edfe8da48bf7b2f78c2f96090db92e9bf69..47d7fd31964b8a70c9fb57d7d0b853962e4eff0e 100644 (file)
@@ -66,7 +66,8 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
     private static final String CLIENT_SECRET = "zn3CrjglwNV1";
     private static final String CLIENT_ID = "hydrawise_app";
     private static final String SCOPE = "all";
-    private final List<HydrawiseControllerListener> controllerListeners = new ArrayList<HydrawiseControllerListener>();
+    private final List<HydrawiseControllerListener> controllerListeners = Collections
+            .synchronizedList(new ArrayList<HydrawiseControllerListener>());
     private final HydrawiseGraphQLClient apiClient;
     private final OAuthClientService oAuthService;
     private @Nullable ScheduledFuture<?> pollFuture;
@@ -116,7 +117,9 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
     }
 
     public void removeControllerListeners(HydrawiseControllerListener listener) {
-        this.controllerListeners.remove(listener);
+        synchronized (controllerListeners) {
+            this.controllerListeners.remove(listener);
+        }
     }
 
     public @Nullable HydrawiseGraphQLClient graphQLClient() {
@@ -197,9 +200,11 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
                 updateStatus(ThingStatus.ONLINE);
             }
             lastData = response.data.me;
-            controllerListeners.forEach(listener -> {
-                listener.onData(response.data.me.controllers);
-            });
+            synchronized (controllerListeners) {
+                controllerListeners.forEach(listener -> {
+                    listener.onData(response.data.me.controllers);
+                });
+            }
         } catch (HydrawiseConnectionException e) {
             if (retry) {
                 logger.debug("Retrying failed poll", e);
index 087b939ba7d188708396907c7e37cfa674b2c23a..0bbd87d9ea9a19618275421b29dd1daeed9a9a98 100644 (file)
@@ -96,11 +96,11 @@ public class HydrawiseControllerHandler extends BaseThingHandler implements Hydr
     public void initialize() {
         HydrawiseControllerConfiguration config = getConfigAs(HydrawiseControllerConfiguration.class);
         controllerId = config.controllerId;
-        Bridge bridge = getBridge();
-        if (bridge != null) {
-            HydrawiseAccountHandler handler = (HydrawiseAccountHandler) bridge.getHandler();
-            if (handler != null) {
-                handler.addControllerListeners(this);
+        HydrawiseAccountHandler handler = getAccountHandler();
+        if (handler != null) {
+            handler.addControllerListeners(this);
+            Bridge bridge = getBridge();
+            if (bridge != null) {
                 if (bridge.getStatus() == ThingStatus.ONLINE) {
                     updateStatus(ThingStatus.ONLINE);
                 } else {
@@ -110,6 +110,15 @@ public class HydrawiseControllerHandler extends BaseThingHandler implements Hydr
         }
     }
 
+    @Override
+    public void dispose() {
+        logger.debug("Controller Handler disposed.");
+        HydrawiseAccountHandler handler = getAccountHandler();
+        if (handler != null) {
+            handler.removeControllerListeners(this);
+        }
+    }
+
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
         logger.debug("handleCommand channel {} Command {}", channelUID.getAsString(), command.toFullString());
index f6f7fddc866ff704b875f90fd8814cab8d2e03fa..5f54f72f7603ce27508f025361111e24c89da876 100644 (file)
                <channels>
                        <channel id="name" typeId="name"/>
                        <channel id="summary" typeId="summary"/>
-                       <channel id="lastcontacttime" typeId="lastcontacttime"/>
+                       <channel id="lastcontact" typeId="lastcontact"/>
                </channels>
        </channel-group-type>
 
        <!-- Controller -->
 
-       <channel-type id="lastcontacttime" advanced="true">
+       <channel-type id="lastcontact" advanced="true">
                <item-type>DateTime</item-type>
                <label>Last Contact Time</label>
                <description>Last contact time of a controller</description>