From 4b0c551065c98552e41ff05d95cb92343a2382ed Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Sat, 14 Oct 2023 19:18:52 +0200 Subject: [PATCH] [hue] Fix channel refresh (API v2) (#15736) * Fix refresh/initial state request Fixes #15735 * Fix channel updates when thing comes online Fixes #15669 Signed-off-by: Jacob Laursen Also-by: Andrew Fiddian-Green --- .../internal/handler/Clip2ThingHandler.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java index 356d9d8ce05c3..6a2e561363ab7 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java @@ -300,19 +300,8 @@ public Collection> 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; } @@ -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. * @@ -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(); } } }