Skip to content

Commit

Permalink
[hue] Fix channel refresh (API v2) (openhab#15736)
Browse files Browse the repository at this point in the history
* Fix refresh/initial state request

Fixes openhab#15735

* Fix channel updates when thing comes online
Fixes openhab#15669

Signed-off-by: Jacob Laursen <[email protected]>
Also-by: Andrew Fiddian-Green <[email protected]>
  • Loading branch information
jlaur authored Oct 14, 2023
1 parent 3110168 commit 4b0c551
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,19 +300,8 @@ public Collection<Class<? extends ThingHandlerService>> getServices() {
@Override
public void handleCommand(ChannelUID channelUID, Command commandParam) {
if (RefreshType.REFRESH.equals(commandParam)) {
if ((thing.getStatus() == ThingStatus.ONLINE) && updateDependenciesDone) {
Future<?> task = updateServiceContributorsTask;
if (Objects.isNull(task) || !task.isDone()) {
cancelTask(updateServiceContributorsTask, false);
updateServiceContributorsTask = scheduler.schedule(() -> {
try {
updateServiceContributors();
} catch (ApiException | AssetNotLoadedException e) {
logger.debug("{} -> handleCommand() error {}", resourceId, e.getMessage(), e);
} catch (InterruptedException e) {
}
}, 3, TimeUnit.SECONDS);
}
if (thing.getStatus() == ThingStatus.ONLINE) {
refreshAllChannels();
}
return;
}
Expand Down Expand Up @@ -524,6 +513,21 @@ public void handleCommand(ChannelUID channelUID, Command commandParam) {
}
}

private void refreshAllChannels() {
if (!updateDependenciesDone) {
return;
}
cancelTask(updateServiceContributorsTask, false);
updateServiceContributorsTask = scheduler.schedule(() -> {
try {
updateServiceContributors();
} catch (ApiException | AssetNotLoadedException e) {
logger.debug("{} -> handleCommand() error {}", resourceId, e.getMessage(), e);
} catch (InterruptedException e) {
}
}, 3, TimeUnit.SECONDS);
}

/**
* Apply device specific work-arounds needed for given command.
*
Expand Down Expand Up @@ -899,11 +903,7 @@ private void updateConnectivityState(Resource resource) {
}
} else if (thing.getStatus() != ThingStatus.ONLINE) {
updateStatus(ThingStatus.ONLINE);
// issue REFRESH command to update all channels
Channel lastUpdateChannel = thing.getChannel(CHANNEL_2_LAST_UPDATED);
if (Objects.nonNull(lastUpdateChannel)) {
handleCommand(lastUpdateChannel.getUID(), RefreshType.REFRESH);
}
refreshAllChannels();
}
}
}
Expand Down

0 comments on commit 4b0c551

Please sign in to comment.