Skip to content

Commit 2e82ac8

Browse files
authored
Refactor Shelly switch name construction (home-assistant#157027)
1 parent 5139e9e commit 2e82ac8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

homeassistant/components/shelly/switch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from .utils import (
4444
async_remove_orphaned_entities,
4545
get_device_entry_gen,
46+
get_rpc_channel_name,
4647
get_virtual_component_ids,
4748
is_block_exclude_from_relay,
4849
is_rpc_exclude_from_relay,
@@ -470,6 +471,7 @@ def __init__(
470471
"""Initialize relay switch."""
471472
super().__init__(coordinator, block, attribute, description)
472473
self.control_result: dict[str, Any] | None = None
474+
self._attr_name = None # Main device entity
473475
self._attr_unique_id: str = f"{coordinator.mac}-{block.description}"
474476

475477
@property
@@ -512,11 +514,9 @@ def __init__(
512514
"""Initialize select."""
513515
super().__init__(coordinator, key, attribute, description)
514516

515-
if (
516-
hasattr(self, "_attr_name")
517-
and description.role != ROLE_GENERIC
518-
and description.key not in ("switch", "script")
519-
):
517+
if description.role == ROLE_GENERIC or description.key in ("switch", "script"):
518+
self._attr_name = get_rpc_channel_name(coordinator.device, key)
519+
elif hasattr(self, "_attr_name"):
520520
delattr(self, "_attr_name")
521521

522522
@property

0 commit comments

Comments
 (0)