diff --git a/homeassistant/components/shelly/binary_sensor.py b/homeassistant/components/shelly/binary_sensor.py index aaae4d057dd8..81945fc2c9bc 100644 --- a/homeassistant/components/shelly/binary_sensor.py +++ b/homeassistant/components/shelly/binary_sensor.py @@ -5,7 +5,6 @@ from __future__ import annotations from dataclasses import dataclass from typing import Final, cast -from aioshelly.block_device import Block from aioshelly.const import RPC_GENERATIONS from homeassistant.components.binary_sensor import ( @@ -21,7 +20,7 @@ from homeassistant.helpers.entity_registry import RegistryEntry from homeassistant.helpers.restore_state import RestoreEntity from .const import CONF_SLEEP_PERIOD, MODEL_FRANKEVER_WATER_VALVE, ROLE_GENERIC -from .coordinator import ShellyBlockCoordinator, ShellyConfigEntry, ShellyRpcCoordinator +from .coordinator import ShellyConfigEntry, ShellyRpcCoordinator from .entity import ( BlockEntityDescription, RestEntityDescription, @@ -83,32 +82,28 @@ class RpcBinarySensor(ShellyRpcAttributeEntity, BinarySensorEntity): """Initialize sensor.""" super().__init__(coordinator, key, attribute, description) - if description.role != ROLE_GENERIC: - if hasattr(self, "_attr_name"): - delattr(self, "_attr_name") - - if not description.role and description.key == "input": + if not description.role: + if description.key == "input": if custom_name := get_rpc_custom_name(coordinator.device, key): self._attr_name = custom_name else: _, _, component_id = get_rpc_key(key) self._attr_translation_placeholders = {"input_number": component_id} self._attr_translation_key = "input_with_number" - - if not description.role and description.key != "input": - translation_placeholders, translation_key = ( - get_entity_translation_attributes( - get_rpc_channel_name(coordinator.device, key), - description.translation_key, - description.device_class, - self._default_to_device_class_name(), + else: + translation_placeholders, translation_key = ( + get_entity_translation_attributes( + get_rpc_channel_name(coordinator.device, key), + description.translation_key, + description.device_class, + self._default_to_device_class_name(), + ) ) - ) - if translation_placeholders: - self._attr_translation_placeholders = translation_placeholders - if translation_key: - self._attr_translation_key = translation_key + if translation_placeholders: + self._attr_translation_placeholders = translation_placeholders + if translation_key: + self._attr_translation_key = translation_key @property def is_on(self) -> bool: @@ -453,19 +448,6 @@ class BlockBinarySensor(ShellyBlockAttributeEntity, BinarySensorEntity): entity_description: BlockBinarySensorDescription - def __init__( - self, - coordinator: ShellyBlockCoordinator, - block: Block, - attribute: str, - description: BlockBinarySensorDescription, - ) -> None: - """Initialize sensor.""" - super().__init__(coordinator, block, attribute, description) - - if hasattr(self, "_attr_name"): - delattr(self, "_attr_name") - @property def is_on(self) -> bool: """Return true if sensor state is on.""" @@ -477,18 +459,6 @@ class RestBinarySensor(ShellyRestAttributeEntity, BinarySensorEntity): entity_description: RestBinarySensorDescription - def __init__( - self, - coordinator: ShellyBlockCoordinator, - attribute: str, - description: RestBinarySensorDescription, - ) -> None: - """Initialize sensor.""" - super().__init__(coordinator, attribute, description) - - if hasattr(self, "_attr_name"): - delattr(self, "_attr_name") - @property def is_on(self) -> bool: """Return true if REST sensor state is on.""" @@ -502,20 +472,6 @@ class BlockSleepingBinarySensor( entity_description: BlockBinarySensorDescription - def __init__( - self, - coordinator: ShellyBlockCoordinator, - block: Block | None, - attribute: str, - description: BlockBinarySensorDescription, - entry: RegistryEntry | None = None, - ) -> None: - """Initialize the sleeping sensor.""" - super().__init__(coordinator, block, attribute, description, entry) - - if hasattr(self, "_attr_name"): - delattr(self, "_attr_name") - async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" await super().async_added_to_hass() @@ -552,9 +508,6 @@ class RpcSleepingBinarySensor( super().__init__(coordinator, key, attribute, description, entry) if coordinator.device.initialized: - if hasattr(self, "_attr_name"): - delattr(self, "_attr_name") - translation_placeholders, translation_key = ( get_entity_translation_attributes( get_rpc_channel_name(coordinator.device, key),