Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hydrawise] concurrent error #13268

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.hydrawise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,7 +117,9 @@ public void addControllerListeners(HydrawiseControllerListener listener) {
}

public void removeControllerListeners(HydrawiseControllerListener listener) {
this.controllerListeners.remove(listener);
synchronized (controllerListeners) {
this.controllerListeners.remove(listener);
}
}

public @Nullable HydrawiseGraphQLClient graphQLClient() {
Expand Down Expand Up @@ -197,9 +200,11 @@ private void poll(boolean retry) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ public HydrawiseControllerHandler(Thing thing) {
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 {
Expand All @@ -110,6 +110,15 @@ public void initialize() {
}
}

@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
<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>
Expand Down