Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hueemulation] Allow Group items to be exposed as devices #6510

Merged
merged 1 commit into from Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/org.openhab.io.hueemulation/README.md
Expand Up @@ -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:

Expand Down
Expand Up @@ -98,6 +98,7 @@
@Path("")
@Produces(MediaType.APPLICATION_JSON)
public class LightsAndGroups implements RegistryChangeListener<Item> {
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<String> ALLOWED_ITEM_TYPES = Stream.of(CoreItemFactory.COLOR, CoreItemFactory.DIMMER,
Expand Down Expand Up @@ -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);

Expand Down
Expand Up @@ -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);
Expand Down