From 856fa7445992245e978173dfbaec7cb5b811443e Mon Sep 17 00:00:00 2001 From: Andrew Fiddian-Green Date: Mon, 16 Dec 2024 19:19:47 +0000 Subject: [PATCH] [hue] Recognise `grouped_motion` and `smart_scene` resources (#17905) Signed-off-by: Andrew Fiddian-Green --- .../api/dto/clip2/enums/ResourceType.java | 1 + .../internal/handler/Clip2ThingHandler.java | 2 +- .../hue/internal/clip2/Clip2DtoTest.java | 17 +++++++++++++++ .../src/test/resources/grouped_motion.json | 21 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 bundles/org.openhab.binding.hue/src/test/resources/grouped_motion.json diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/enums/ResourceType.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/enums/ResourceType.java index 5dcd2842ac9..426e36f95ef 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/enums/ResourceType.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/enums/ResourceType.java @@ -41,6 +41,7 @@ public enum ResourceType { GEOFENCE_CLIENT, GEOLOCATION, GROUPED_LIGHT, + GROUPED_MOTION, HOMEKIT, LIGHT, LIGHT_LEVEL, 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 947454f4fdd..285bf635a06 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 @@ -765,7 +765,7 @@ public class Clip2ThingHandler extends BaseThingHandler { * @param fullResources the full list of resources of the given type. */ public void onResourcesList(ResourceType resourceType, List fullResources) { - if (resourceType == ResourceType.SCENE) { + if (SUPPORTED_SCENE_TYPES.contains(resourceType)) { updateSceneContributors(fullResources); } else { fullResources.stream().filter(r -> resourceId.equals(r.getId())).findAny() diff --git a/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java b/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java index 78b33e3d9ba..6104c6fbe10 100644 --- a/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java +++ b/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java @@ -914,4 +914,21 @@ class Clip2DtoTest { assertNotNull(list); assertEquals(2, list.size()); } + + @Test + void testGroupedMotion() { + String json = load(ResourceType.GROUPED_MOTION.name().toLowerCase()); + Resources resources = GSON.fromJson(json, Resources.class); + assertNotNull(resources); + List list = resources.getResources(); + assertNotNull(list); + assertEquals(1, list.size()); + Resource item = list.get(0); + assertEquals(ResourceType.GROUPED_MOTION, item.getType()); + Boolean enabled = item.getEnabled(); + assertNotNull(enabled); + assertTrue(enabled); + assertEquals(OnOffType.ON, item.getMotionState()); + assertEquals(new DateTimeType("2024-12-13T11:01:25.156Z"), item.getMotionLastUpdatedState(ZoneId.of("UTC"))); + } } diff --git a/bundles/org.openhab.binding.hue/src/test/resources/grouped_motion.json b/bundles/org.openhab.binding.hue/src/test/resources/grouped_motion.json new file mode 100644 index 00000000000..9b052e2aa91 --- /dev/null +++ b/bundles/org.openhab.binding.hue/src/test/resources/grouped_motion.json @@ -0,0 +1,21 @@ +{ + "errors": [], + "data": [ + { + "id": "aab07fb5-b0c1-400b-828f-a9e0a05394f9", + "id_v1": "/sensors/5", + "enabled": true, + "motion": { + "motion_report": { + "changed": "2024-12-13T11:01:25.156Z", + "motion": true + } + }, + "owner": { + "rid": "bb9b4bb4-b0c8-4b6a-8dc0-85add8f77964", + "rtype": "bridge_home" + }, + "type": "grouped_motion" + } + ] +}