mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 03:14:07 +01:00
[Hydrawise] concurrent error (#13268)
* 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>
This commit is contained in:
parent
8baa500998
commit
b63e420abf
@ -172,7 +172,7 @@ Group SprinklerSensors "Sensors" (Sprinkler)
|
|||||||
Group SprinkerForecast "Forecast" (Sprinkler)
|
Group SprinkerForecast "Forecast" (Sprinkler)
|
||||||
|
|
||||||
String SprinkerControllerStatus "Status [%s]" (SprinklerController) {channel="hydrawise:controller:myaccount:123456:controller#status"}
|
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"}
|
Switch SprinklerSensor1 "Sprinler Sensor" (SprinklerSensors) {channel="hydrawise:controller:myaccount:123456:sensor1#active"}
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
|||||||
private static final String CLIENT_SECRET = "zn3CrjglwNV1";
|
private static final String CLIENT_SECRET = "zn3CrjglwNV1";
|
||||||
private static final String CLIENT_ID = "hydrawise_app";
|
private static final String CLIENT_ID = "hydrawise_app";
|
||||||
private static final String SCOPE = "all";
|
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 HydrawiseGraphQLClient apiClient;
|
||||||
private final OAuthClientService oAuthService;
|
private final OAuthClientService oAuthService;
|
||||||
private @Nullable ScheduledFuture<?> pollFuture;
|
private @Nullable ScheduledFuture<?> pollFuture;
|
||||||
@ -116,8 +117,10 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeControllerListeners(HydrawiseControllerListener listener) {
|
public void removeControllerListeners(HydrawiseControllerListener listener) {
|
||||||
|
synchronized (controllerListeners) {
|
||||||
this.controllerListeners.remove(listener);
|
this.controllerListeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable HydrawiseGraphQLClient graphQLClient() {
|
public @Nullable HydrawiseGraphQLClient graphQLClient() {
|
||||||
return apiClient;
|
return apiClient;
|
||||||
@ -197,9 +200,11 @@ public class HydrawiseAccountHandler extends BaseBridgeHandler implements Access
|
|||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
}
|
}
|
||||||
lastData = response.data.me;
|
lastData = response.data.me;
|
||||||
|
synchronized (controllerListeners) {
|
||||||
controllerListeners.forEach(listener -> {
|
controllerListeners.forEach(listener -> {
|
||||||
listener.onData(response.data.me.controllers);
|
listener.onData(response.data.me.controllers);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
} catch (HydrawiseConnectionException e) {
|
} catch (HydrawiseConnectionException e) {
|
||||||
if (retry) {
|
if (retry) {
|
||||||
logger.debug("Retrying failed poll", e);
|
logger.debug("Retrying failed poll", e);
|
||||||
|
@ -96,11 +96,11 @@ public class HydrawiseControllerHandler extends BaseThingHandler implements Hydr
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
HydrawiseControllerConfiguration config = getConfigAs(HydrawiseControllerConfiguration.class);
|
HydrawiseControllerConfiguration config = getConfigAs(HydrawiseControllerConfiguration.class);
|
||||||
controllerId = config.controllerId;
|
controllerId = config.controllerId;
|
||||||
Bridge bridge = getBridge();
|
HydrawiseAccountHandler handler = getAccountHandler();
|
||||||
if (bridge != null) {
|
|
||||||
HydrawiseAccountHandler handler = (HydrawiseAccountHandler) bridge.getHandler();
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
handler.addControllerListeners(this);
|
handler.addControllerListeners(this);
|
||||||
|
Bridge bridge = getBridge();
|
||||||
|
if (bridge != null) {
|
||||||
if (bridge.getStatus() == ThingStatus.ONLINE) {
|
if (bridge.getStatus() == ThingStatus.ONLINE) {
|
||||||
updateStatus(ThingStatus.ONLINE);
|
updateStatus(ThingStatus.ONLINE);
|
||||||
} else {
|
} 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
|
@Override
|
||||||
public void handleCommand(ChannelUID channelUID, Command command) {
|
public void handleCommand(ChannelUID channelUID, Command command) {
|
||||||
logger.debug("handleCommand channel {} Command {}", channelUID.getAsString(), command.toFullString());
|
logger.debug("handleCommand channel {} Command {}", channelUID.getAsString(), command.toFullString());
|
||||||
|
@ -68,13 +68,13 @@
|
|||||||
<channels>
|
<channels>
|
||||||
<channel id="name" typeId="name"/>
|
<channel id="name" typeId="name"/>
|
||||||
<channel id="summary" typeId="summary"/>
|
<channel id="summary" typeId="summary"/>
|
||||||
<channel id="lastcontacttime" typeId="lastcontacttime"/>
|
<channel id="lastcontact" typeId="lastcontact"/>
|
||||||
</channels>
|
</channels>
|
||||||
</channel-group-type>
|
</channel-group-type>
|
||||||
|
|
||||||
<!-- Controller -->
|
<!-- Controller -->
|
||||||
|
|
||||||
<channel-type id="lastcontacttime" advanced="true">
|
<channel-type id="lastcontact" advanced="true">
|
||||||
<item-type>DateTime</item-type>
|
<item-type>DateTime</item-type>
|
||||||
<label>Last Contact Time</label>
|
<label>Last Contact Time</label>
|
||||||
<description>Last contact time of a controller</description>
|
<description>Last contact time of a controller</description>
|
||||||
|
Loading…
Reference in New Issue
Block a user