From f45630064a4959c294ac01f9835df68190ac875d Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 12 Dec 2023 08:46:29 +0100 Subject: [PATCH] Fix scene channel updates (#16018) Fixes #16000 Also-by: Andrew Fiddian-Green Signed-off-by: Jacob Laursen --- .../internal/handler/Clip2BridgeHandler.java | 2 +- .../internal/handler/Clip2ThingHandler.java | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java index e6dd7181e..d0374e362 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2BridgeHandler.java @@ -537,7 +537,7 @@ public class Clip2BridgeHandler extends BaseBridgeHandler { } getThing().getThings().forEach(thing -> { if (thing.getHandler() instanceof Clip2ThingHandler clip2ThingHandler) { - resources.forEach(resource -> clip2ThingHandler.onResource(resource)); + clip2ThingHandler.onResources(resources); } }); } 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 30a49dc3c..f3e1291bc 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 @@ -631,12 +631,38 @@ public class Clip2ThingHandler extends BaseThingHandler { } } + /** + * Update the channel state depending on new resources sent from the bridge. + * + * @param resources a collection of Resource objects containing the new state. + */ + public void onResources(Collection resources) { + boolean sceneActivated = resources.stream().anyMatch(r -> sceneContributorsCache.containsKey(r.getId()) + && (r.getSceneActive().orElse(false) || r.getSmartSceneActive().orElse(false))); + for (Resource resource : resources) { + // Skip scene deactivation when we have also received a scene activation. + boolean updateChannels = !sceneActivated || !sceneContributorsCache.containsKey(resource.getId()) + || resource.getSceneActive().orElse(false) || resource.getSmartSceneActive().orElse(false); + onResource(resource, updateChannels); + } + } + /** * Update the channel state depending on a new resource sent from the bridge. * * @param resource a Resource object containing the new state. */ - public void onResource(Resource resource) { + private void onResource(Resource resource) { + onResource(resource, true); + } + + /** + * Update the channel state depending on a new resource sent from the bridge. + * + * @param resource a Resource object containing the new state. + * @param updateChannels update channels (otherwise only update cache/properties). + */ + private void onResource(Resource resource, boolean updateChannels) { if (disposing) { return; } @@ -658,7 +684,7 @@ public class Clip2ThingHandler extends BaseThingHandler { Resource cachedResource = getResourceFromCache(resource); if (cachedResource != null) { Setters.setResource(resource, cachedResource); - resourceConsumed = updateChannels(resource); + resourceConsumed = updateChannels && updateChannels(resource); putResourceToCache(resource); if (ResourceType.LIGHT == resource.getType() && !updateLightPropertiesDone) { updateLightProperties(resource);