|
20 | 20 | from homeassistant.helpers.typing import StateType |
21 | 21 | from homeassistant.helpers.update_coordinator import CoordinatorEntity |
22 | 22 |
|
23 | | -from .const import CONF_SLEEP_PERIOD, DOMAIN, LOGGER |
| 23 | +from .const import CONF_SLEEP_PERIOD, DOMAIN, LOGGER, ROLE_GENERIC |
24 | 24 | from .coordinator import ShellyBlockCoordinator, ShellyConfigEntry, ShellyRpcCoordinator |
25 | 25 | from .utils import ( |
26 | 26 | async_remove_shelly_entity, |
27 | 27 | get_block_device_info, |
28 | | - get_block_entity_name, |
| 28 | + get_rpc_channel_name, |
29 | 29 | get_rpc_device_info, |
30 | | - get_rpc_entity_name, |
| 30 | + get_rpc_key, |
31 | 31 | get_rpc_key_instances, |
32 | 32 | get_rpc_role_by_key, |
33 | 33 | ) |
@@ -371,7 +371,7 @@ def __init__(self, coordinator: ShellyBlockCoordinator, block: Block) -> None: |
371 | 371 | """Initialize Shelly entity.""" |
372 | 372 | super().__init__(coordinator) |
373 | 373 | self.block = block |
374 | | - self._attr_name = get_block_entity_name(coordinator.device, block) |
| 374 | + |
375 | 375 | self._attr_device_info = get_entity_block_device_info(coordinator, block) |
376 | 376 | self._attr_unique_id = f"{coordinator.mac}-{block.description}" |
377 | 377 |
|
@@ -413,9 +413,9 @@ def __init__(self, coordinator: ShellyRpcCoordinator, key: str) -> None: |
413 | 413 | """Initialize Shelly entity.""" |
414 | 414 | super().__init__(coordinator) |
415 | 415 | self.key = key |
| 416 | + |
416 | 417 | self._attr_device_info = get_entity_rpc_device_info(coordinator, key) |
417 | 418 | self._attr_unique_id = f"{coordinator.mac}-{key}" |
418 | | - self._attr_name = get_rpc_entity_name(coordinator.device, key) |
419 | 419 |
|
420 | 420 | @property |
421 | 421 | def available(self) -> bool: |
@@ -467,9 +467,6 @@ def __init__( |
467 | 467 | self.entity_description = description |
468 | 468 |
|
469 | 469 | self._attr_unique_id: str = f"{super().unique_id}-{self.attribute}" |
470 | | - self._attr_name = get_block_entity_name( |
471 | | - coordinator.device, block, description.name |
472 | | - ) |
473 | 470 |
|
474 | 471 | @property |
475 | 472 | def attribute_value(self) -> StateType: |
@@ -507,9 +504,7 @@ def __init__( |
507 | 504 | self.block_coordinator = coordinator |
508 | 505 | self.attribute = attribute |
509 | 506 | self.entity_description = description |
510 | | - self._attr_name = get_block_entity_name( |
511 | | - coordinator.device, None, description.name |
512 | | - ) |
| 507 | + |
513 | 508 | self._attr_unique_id = f"{coordinator.mac}-{attribute}" |
514 | 509 | self._attr_device_info = get_entity_block_device_info(coordinator) |
515 | 510 | self._last_value = None |
@@ -546,13 +541,13 @@ def __init__( |
546 | 541 | self.attribute = attribute |
547 | 542 | self.entity_description = description |
548 | 543 |
|
| 544 | + if description.role == ROLE_GENERIC: |
| 545 | + self._attr_name = get_rpc_channel_name(coordinator.device, key) |
| 546 | + |
549 | 547 | self._attr_unique_id = f"{super().unique_id}-{attribute}" |
550 | | - self._attr_name = get_rpc_entity_name( |
551 | | - coordinator.device, key, description.name, description.role |
552 | | - ) |
553 | 548 | self._last_value = None |
554 | | - id_key = key.split(":")[-1] |
555 | | - self._id = int(id_key) if id_key.isnumeric() else None |
| 549 | + has_id, _, component_id = get_rpc_key(key) |
| 550 | + self._id = int(component_id) if has_id and component_id.isnumeric() else None |
556 | 551 |
|
557 | 552 | if description.unit is not None: |
558 | 553 | self._attr_native_unit_of_measurement = description.unit( |
@@ -626,9 +621,6 @@ def __init__( |
626 | 621 | self._attr_unique_id = ( |
627 | 622 | f"{self.coordinator.mac}-{block.description}-{attribute}" |
628 | 623 | ) |
629 | | - self._attr_name = get_block_entity_name( |
630 | | - coordinator.device, block, description.name |
631 | | - ) |
632 | 624 | elif entry is not None: |
633 | 625 | self._attr_unique_id = entry.unique_id |
634 | 626 |
|
@@ -689,11 +681,7 @@ def __init__( |
689 | 681 | self._attr_unique_id = f"{coordinator.mac}-{key}-{attribute}" |
690 | 682 | self._last_value = None |
691 | 683 |
|
692 | | - if coordinator.device.initialized: |
693 | | - self._attr_name = get_rpc_entity_name( |
694 | | - coordinator.device, key, description.name |
695 | | - ) |
696 | | - elif entry is not None: |
| 684 | + if not coordinator.device.initialized and entry is not None: |
697 | 685 | self._attr_name = cast(str, entry.original_name) |
698 | 686 |
|
699 | 687 | async def async_update(self) -> None: |
|
0 commit comments