Skip to content

Commit

Permalink
[homekit] add support for group switches (openhab#7967)
Browse files Browse the repository at this point in the history
Signed-off-by: Eugen Freiter <[email protected]>
Signed-off-by: MPH80 <[email protected]>
  • Loading branch information
yfre authored and MPH80 committed Aug 3, 2020
1 parent 6349b57 commit c96d3ea
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ private void createRootAccessories(Item item) {
final List<Entry<HomekitAccessoryType, HomekitCharacteristicType>> accessoryTypes = HomekitAccessoryFactory
.getAccessoryTypes(item, metadataRegistry);
final List<GroupItem> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public static List<GroupItem> 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();
Expand Down

0 comments on commit c96d3ea

Please sign in to comment.