From 122c213f402ead1eeac0ace8e07ef93742dd7b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolai=20Gr=C3=B8dum?= Date: Wed, 4 Dec 2019 23:30:56 +0100 Subject: [PATCH] Added the tag "Huelight" which allows Group items to be exposed as a device. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolai Grødum --- bundles/org.openhab.io.hueemulation/README.md | 1 + .../hueemulation/internal/rest/LightsAndGroups.java | 3 ++- .../internal/rest/LightsAndGroupsTests.java | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.io.hueemulation/README.md b/bundles/org.openhab.io.hueemulation/README.md index a1ab1944862c..6671f9e7d815 100644 --- a/bundles/org.openhab.io.hueemulation/README.md +++ b/bundles/org.openhab.io.hueemulation/README.md @@ -32,6 +32,7 @@ By default the pairing mode disables itself after 1 minute (can be configured). It is important to note that you are exposing *Items* not *Things* or *Channels*. Only Color, Dimmer, Rollershutter, Switch and Group type *Items* are supported. +Group type items require the "Huelight" tag to be exposed as devices instead of Groups. This service can emulate 3 different devices: diff --git a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroups.java b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroups.java index 3aaf4f07505f..85a57b0eef78 100644 --- a/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroups.java +++ b/bundles/org.openhab.io.hueemulation/src/main/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroups.java @@ -98,6 +98,7 @@ @Path("") @Produces(MediaType.APPLICATION_JSON) public class LightsAndGroups implements RegistryChangeListener { + public static final String EXPOSE_AS_DEVICE_TAG = "huelight"; private final Logger logger = LoggerFactory.getLogger(LightsAndGroups.class); private static final String ITEM_TYPE_GROUP = "Group"; private static final Set ALLOWED_ITEM_TYPES = Stream.of(CoreItemFactory.COLOR, CoreItemFactory.DIMMER, @@ -153,7 +154,7 @@ public synchronized void added(Item newElement) { String hueID = cs.mapItemUIDtoHueID(element); - if (element instanceof GroupItem) { + if (element instanceof GroupItem && !element.hasTag(EXPOSE_AS_DEVICE_TAG)) { GroupItem g = (GroupItem) element; HueGroupEntry group = new HueGroupEntry(g.getName(), g, deviceType); diff --git a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroupsTests.java b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroupsTests.java index a80f9c8244ee..9208c6eb5df4 100644 --- a/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroupsTests.java +++ b/bundles/org.openhab.io.hueemulation/src/test/java/org/openhab/io/hueemulation/internal/rest/LightsAndGroupsTests.java @@ -126,6 +126,17 @@ public void addGroupSwitchableByTag() { assertThat(device.action, is(instanceOf(HueStatePlug.class))); } + @Test + public void addDeviceAsGroupSwitchableByTag() { + GroupItem item = new GroupItem("group1", new SwitchItem("switch1")); + item.addTag("Switchable"); + item.addTag("Huelight"); + itemRegistry.add(item); + HueLightEntry device = cs.ds.lights.get(cs.mapItemUIDtoHueID(item)); + assertThat(device.item, is(item)); + assertThat(device.state, is(instanceOf(HueStatePlug.class))); + } + @Test public void addGroupWithoutTypeByTag() { GroupItem item = new GroupItem("group1", null);