Fix area search for entities of devices (#114394)
This commit is contained in:
parent
192fad040a
commit
3df03f5be5
2 changed files with 27 additions and 6 deletions
|
@ -136,6 +136,9 @@ class Searcher:
|
||||||
# Scripts referencing this area
|
# Scripts referencing this area
|
||||||
self._add(ItemType.SCRIPT, script.scripts_with_area(self.hass, area_id))
|
self._add(ItemType.SCRIPT, script.scripts_with_area(self.hass, area_id))
|
||||||
|
|
||||||
|
# Entity in this area, will extend this with the entities of the devices in this area
|
||||||
|
entity_entries = er.async_entries_for_area(self._entity_registry, area_id)
|
||||||
|
|
||||||
# Devices in this area
|
# Devices in this area
|
||||||
for device in dr.async_entries_for_area(self._device_registry, area_id):
|
for device in dr.async_entries_for_area(self._device_registry, area_id):
|
||||||
self._add(ItemType.DEVICE, device.id)
|
self._add(ItemType.DEVICE, device.id)
|
||||||
|
@ -160,10 +163,10 @@ class Searcher:
|
||||||
# Skip the entity if it's in a different area
|
# Skip the entity if it's in a different area
|
||||||
if entity_entry.area_id is not None:
|
if entity_entry.area_id is not None:
|
||||||
continue
|
continue
|
||||||
self._add(ItemType.ENTITY, entity_entry.entity_id)
|
entity_entries.append(entity_entry)
|
||||||
|
|
||||||
# Entities in this area
|
# Process entities in this area
|
||||||
for entity_entry in er.async_entries_for_area(self._entity_registry, area_id):
|
for entity_entry in entity_entries:
|
||||||
self._add(ItemType.ENTITY, entity_entry.entity_id)
|
self._add(ItemType.ENTITY, entity_entry.entity_id)
|
||||||
|
|
||||||
# If this entity also exists as a resource, we add it.
|
# If this entity also exists as a resource, we add it.
|
||||||
|
|
|
@ -496,11 +496,14 @@ async def test_search(
|
||||||
ItemType.SCRIPT: {script_scene_entity.entity_id, "script.nested"},
|
ItemType.SCRIPT: {script_scene_entity.entity_id, "script.nested"},
|
||||||
}
|
}
|
||||||
assert search(ItemType.AREA, living_room_area.id) == {
|
assert search(ItemType.AREA, living_room_area.id) == {
|
||||||
ItemType.AUTOMATION: {"automation.wled_device"},
|
ItemType.AUTOMATION: {"automation.wled_device", "automation.wled_entity"},
|
||||||
ItemType.CONFIG_ENTRY: {wled_config_entry.entry_id},
|
ItemType.CONFIG_ENTRY: {wled_config_entry.entry_id},
|
||||||
ItemType.DEVICE: {wled_device.id},
|
ItemType.DEVICE: {wled_device.id},
|
||||||
ItemType.ENTITY: {wled_segment_1_entity.entity_id},
|
ItemType.ENTITY: {wled_segment_1_entity.entity_id},
|
||||||
ItemType.FLOOR: {first_floor.floor_id},
|
ItemType.FLOOR: {first_floor.floor_id},
|
||||||
|
ItemType.GROUP: {"group.wled", "group.wled_hue"},
|
||||||
|
ItemType.SCENE: {"scene.scene_wled_seg_1", scene_wled_hue_entity.entity_id},
|
||||||
|
ItemType.SCRIPT: {"script.wled"},
|
||||||
}
|
}
|
||||||
assert search(ItemType.AREA, kitchen_area.id) == {
|
assert search(ItemType.AREA, kitchen_area.id) == {
|
||||||
ItemType.AUTOMATION: {"automation.area"},
|
ItemType.AUTOMATION: {"automation.area"},
|
||||||
|
@ -511,7 +514,9 @@ async def test_search(
|
||||||
hue_segment_2_entity.entity_id,
|
hue_segment_2_entity.entity_id,
|
||||||
},
|
},
|
||||||
ItemType.FLOOR: {first_floor.floor_id},
|
ItemType.FLOOR: {first_floor.floor_id},
|
||||||
ItemType.SCRIPT: {"script.area", "script.device"},
|
ItemType.GROUP: {"group.hue", "group.wled_hue"},
|
||||||
|
ItemType.SCENE: {"scene.scene_hue_seg_1", scene_wled_hue_entity.entity_id},
|
||||||
|
ItemType.SCRIPT: {"script.area", "script.device", "script.hue"},
|
||||||
}
|
}
|
||||||
|
|
||||||
assert not search(ItemType.AUTOMATION, "automation.unknown")
|
assert not search(ItemType.AUTOMATION, "automation.unknown")
|
||||||
|
@ -726,6 +731,7 @@ async def test_search(
|
||||||
"automation.area",
|
"automation.area",
|
||||||
"automation.floor",
|
"automation.floor",
|
||||||
"automation.wled_device",
|
"automation.wled_device",
|
||||||
|
"automation.wled_entity",
|
||||||
},
|
},
|
||||||
ItemType.CONFIG_ENTRY: {hue_config_entry.entry_id, wled_config_entry.entry_id},
|
ItemType.CONFIG_ENTRY: {hue_config_entry.entry_id, wled_config_entry.entry_id},
|
||||||
ItemType.DEVICE: {hue_device.id, wled_device.id},
|
ItemType.DEVICE: {hue_device.id, wled_device.id},
|
||||||
|
@ -734,7 +740,19 @@ async def test_search(
|
||||||
hue_segment_1_entity.entity_id,
|
hue_segment_1_entity.entity_id,
|
||||||
hue_segment_2_entity.entity_id,
|
hue_segment_2_entity.entity_id,
|
||||||
},
|
},
|
||||||
ItemType.SCRIPT: {"script.device", "script.area", "script.floor"},
|
ItemType.GROUP: {"group.hue", "group.wled", "group.wled_hue"},
|
||||||
|
ItemType.SCENE: {
|
||||||
|
"scene.scene_hue_seg_1",
|
||||||
|
"scene.scene_wled_seg_1",
|
||||||
|
scene_wled_hue_entity.entity_id,
|
||||||
|
},
|
||||||
|
ItemType.SCRIPT: {
|
||||||
|
"script.device",
|
||||||
|
"script.area",
|
||||||
|
"script.floor",
|
||||||
|
"script.hue",
|
||||||
|
"script.wled",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
assert search(ItemType.FLOOR, second_floor.floor_id) == {
|
assert search(ItemType.FLOOR, second_floor.floor_id) == {
|
||||||
ItemType.AREA: {bedroom_area.id},
|
ItemType.AREA: {bedroom_area.id},
|
||||||
|
|
Loading…
Add table
Reference in a new issue