From 96000ce085c5a6a556af23d1251536243180d754 Mon Sep 17 00:00:00 2001 From: eugen Date: Wed, 24 Jun 2020 23:56:14 +0200 Subject: [PATCH] [homekit] add support for group switches (#7967) Signed-off-by: Eugen Freiter Signed-off-by: Daan Meijer --- .../openhab/io/homekit/internal/HomekitChangeListener.java | 6 +++--- .../org/openhab/io/homekit/internal/HomekitTaggedItem.java | 3 ++- .../internal/accessories/HomekitAccessoryFactory.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitChangeListener.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitChangeListener.java index 41b6c47c3a34a..39a944255e7cd 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitChangeListener.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitChangeListener.java @@ -227,9 +227,9 @@ private void createRootAccessories(Item item) { final List> accessoryTypes = HomekitAccessoryFactory .getAccessoryTypes(item, metadataRegistry); final List groups = HomekitAccessoryFactory.getAccessoryGroups(item, itemRegistry, metadataRegistry); - logger.trace("Item {} has groups {}", item.getName(), groups); - if (!accessoryTypes.isEmpty() && groups.isEmpty()) { // it has homekit accessory type and is not part of bigger - // homekit group item + if (!accessoryTypes.isEmpty() && groups.stream().noneMatch(g -> g.getBaseItem() != null)) { + // it has homekit accessory type and is not part of bigger homekit group item without baseItem, i.e. not + // Group:Switch logger.trace("Item {} is a HomeKit accessory of types {}", item.getName(), accessoryTypes); final HomekitOHItemProxy itemProxy = new HomekitOHItemProxy(item); accessoryTypes.stream().forEach(rootAccessory -> createRootAccessory(new HomekitTaggedItem(itemProxy, diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java index 00561f8021e1b..44f9d2c0fbc48 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitTaggedItem.java @@ -92,7 +92,8 @@ public HomekitTaggedItem(HomekitOHItemProxy item, HomekitAccessoryType homekitAc } public boolean isGroup() { - return (isAccessory() && (proxyItem.getItem() instanceof GroupItem)); + return (isAccessory() && (proxyItem.getItem() instanceof GroupItem) + && ((GroupItem) proxyItem.getItem()).getBaseItem() == null); } public HomekitAccessoryType getAccessoryType() { diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java index cb8a406a099b5..46b294a01f6ba 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java @@ -262,7 +262,7 @@ public static List getAccessoryGroups(Item item, ItemRegistry itemReg MetadataRegistry metadataRegistry) { return item.getGroupNames().stream().flatMap(name -> { Item groupItem = itemRegistry.get(name); - if (groupItem instanceof GroupItem) { + if ((groupItem instanceof GroupItem) && ((GroupItem) groupItem).getBaseItem() == null) { return Stream.of((GroupItem) groupItem); } else { return Stream.empty();