Skip to content

Commit 4847ec6

Browse files
authored
Merge pull request #7 from wbyoung/find-entities-via-translation-key
Search related entities by `translation_key`
2 parents ff00809 + 82b4af4 commit 4847ec6

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

custom_components/lampie/orchestrator.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,18 @@ def switch_info(self, switch_id: SwitchId) -> LampieSwitchInfo:
164164
local_protetction_id = None
165165
disable_clear_notification_id = None
166166

167+
_LOGGER.debug(
168+
"searching %s related entries: %s",
169+
switch_id,
170+
[(entry.unique_id, entry.translation_key) for entry in entity_entries],
171+
)
172+
167173
for entity_entry in entity_entries:
168-
if entity_entry.unique_id.endswith("-local_protection"):
174+
if entity_entry.translation_key == "local_protection":
169175
local_protetction_id = entity_entry.entity_id
170-
if entity_entry.unique_id.endswith(
171-
"-disable_clear_notifications_double_tap"
176+
if (
177+
entity_entry.translation_key
178+
== "disable_clear_notifications_double_tap"
172179
):
173180
disable_clear_notification_id = entity_entry.entity_id
174181

tests/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ def add_mock_switch(
7979
ZHA_DOMAIN,
8080
f"{object_id}-local_protection",
8181
suggested_object_id=f"{object_id}_local_protection",
82+
translation_key="local_protection",
8283
device_id=device_entry.id,
8384
)
8485
entity_registry.async_get_or_create(
8586
"switch",
8687
ZHA_DOMAIN,
8788
f"{object_id}-disable_clear_notifications_double_tap",
8889
suggested_object_id=f"{object_id}_disable_config_2x_tap_to_clear_notifications",
90+
translation_key="disable_clear_notifications_double_tap",
8991
device_id=device_entry.id,
9092
)
9193
return switch

0 commit comments

Comments
 (0)