Skip to content

Commit 6c4296a

Browse files
authored
Remove Shelly binary sensor name removal (home-assistant#157065)
Signed-off-by: David Rapan <[email protected]>
1 parent e780e3d commit 6c4296a

File tree

1 file changed

+15
-62
lines changed

1 file changed

+15
-62
lines changed

homeassistant/components/shelly/binary_sensor.py

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from dataclasses import dataclass
66
from typing import Final, cast
77

8-
from aioshelly.block_device import Block
98
from aioshelly.const import RPC_GENERATIONS
109

1110
from homeassistant.components.binary_sensor import (
@@ -21,7 +20,7 @@
2120
from homeassistant.helpers.restore_state import RestoreEntity
2221

2322
from .const import CONF_SLEEP_PERIOD, MODEL_FRANKEVER_WATER_VALVE, ROLE_GENERIC
24-
from .coordinator import ShellyBlockCoordinator, ShellyConfigEntry, ShellyRpcCoordinator
23+
from .coordinator import ShellyConfigEntry, ShellyRpcCoordinator
2524
from .entity import (
2625
BlockEntityDescription,
2726
RestEntityDescription,
@@ -83,32 +82,28 @@ def __init__(
8382
"""Initialize sensor."""
8483
super().__init__(coordinator, key, attribute, description)
8584

86-
if description.role != ROLE_GENERIC:
87-
if hasattr(self, "_attr_name"):
88-
delattr(self, "_attr_name")
89-
90-
if not description.role and description.key == "input":
85+
if not description.role:
86+
if description.key == "input":
9187
if custom_name := get_rpc_custom_name(coordinator.device, key):
9288
self._attr_name = custom_name
9389
else:
9490
_, _, component_id = get_rpc_key(key)
9591
self._attr_translation_placeholders = {"input_number": component_id}
9692
self._attr_translation_key = "input_with_number"
97-
98-
if not description.role and description.key != "input":
99-
translation_placeholders, translation_key = (
100-
get_entity_translation_attributes(
101-
get_rpc_channel_name(coordinator.device, key),
102-
description.translation_key,
103-
description.device_class,
104-
self._default_to_device_class_name(),
93+
else:
94+
translation_placeholders, translation_key = (
95+
get_entity_translation_attributes(
96+
get_rpc_channel_name(coordinator.device, key),
97+
description.translation_key,
98+
description.device_class,
99+
self._default_to_device_class_name(),
100+
)
105101
)
106-
)
107102

108-
if translation_placeholders:
109-
self._attr_translation_placeholders = translation_placeholders
110-
if translation_key:
111-
self._attr_translation_key = translation_key
103+
if translation_placeholders:
104+
self._attr_translation_placeholders = translation_placeholders
105+
if translation_key:
106+
self._attr_translation_key = translation_key
112107

113108
@property
114109
def is_on(self) -> bool:
@@ -453,19 +448,6 @@ class BlockBinarySensor(ShellyBlockAttributeEntity, BinarySensorEntity):
453448

454449
entity_description: BlockBinarySensorDescription
455450

456-
def __init__(
457-
self,
458-
coordinator: ShellyBlockCoordinator,
459-
block: Block,
460-
attribute: str,
461-
description: BlockBinarySensorDescription,
462-
) -> None:
463-
"""Initialize sensor."""
464-
super().__init__(coordinator, block, attribute, description)
465-
466-
if hasattr(self, "_attr_name"):
467-
delattr(self, "_attr_name")
468-
469451
@property
470452
def is_on(self) -> bool:
471453
"""Return true if sensor state is on."""
@@ -477,18 +459,6 @@ class RestBinarySensor(ShellyRestAttributeEntity, BinarySensorEntity):
477459

478460
entity_description: RestBinarySensorDescription
479461

480-
def __init__(
481-
self,
482-
coordinator: ShellyBlockCoordinator,
483-
attribute: str,
484-
description: RestBinarySensorDescription,
485-
) -> None:
486-
"""Initialize sensor."""
487-
super().__init__(coordinator, attribute, description)
488-
489-
if hasattr(self, "_attr_name"):
490-
delattr(self, "_attr_name")
491-
492462
@property
493463
def is_on(self) -> bool:
494464
"""Return true if REST sensor state is on."""
@@ -502,20 +472,6 @@ class BlockSleepingBinarySensor(
502472

503473
entity_description: BlockBinarySensorDescription
504474

505-
def __init__(
506-
self,
507-
coordinator: ShellyBlockCoordinator,
508-
block: Block | None,
509-
attribute: str,
510-
description: BlockBinarySensorDescription,
511-
entry: RegistryEntry | None = None,
512-
) -> None:
513-
"""Initialize the sleeping sensor."""
514-
super().__init__(coordinator, block, attribute, description, entry)
515-
516-
if hasattr(self, "_attr_name"):
517-
delattr(self, "_attr_name")
518-
519475
async def async_added_to_hass(self) -> None:
520476
"""Handle entity which will be added."""
521477
await super().async_added_to_hass()
@@ -552,9 +508,6 @@ def __init__(
552508
super().__init__(coordinator, key, attribute, description, entry)
553509

554510
if coordinator.device.initialized:
555-
if hasattr(self, "_attr_name"):
556-
delattr(self, "_attr_name")
557-
558511
translation_placeholders, translation_key = (
559512
get_entity_translation_attributes(
560513
get_rpc_channel_name(coordinator.device, key),

0 commit comments

Comments
 (0)