diff --git a/homeassistant/components/screenlogic/binary_sensor.py b/homeassistant/components/screenlogic/binary_sensor.py index cb73fab90ee..096c2c22918 100644 --- a/homeassistant/components/screenlogic/binary_sensor.py +++ b/homeassistant/components/screenlogic/binary_sensor.py @@ -22,7 +22,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN as SL_DOMAIN from .coordinator import ScreenlogicDataUpdateCoordinator from .entity import ( - ScreenlogicEntity, + ScreenLogicEntity, ScreenLogicEntityDescription, ScreenLogicPushEntity, ScreenLogicPushEntityDescription, @@ -232,7 +232,7 @@ async def async_setup_entry( async_add_entities(entities) -class ScreenLogicBinarySensor(ScreenlogicEntity, BinarySensorEntity): +class ScreenLogicBinarySensor(ScreenLogicEntity, BinarySensorEntity): """Representation of a ScreenLogic binary sensor entity.""" entity_description: ScreenLogicBinarySensorDescription diff --git a/homeassistant/components/screenlogic/entity.py b/homeassistant/components/screenlogic/entity.py index 06551c2736b..fc2c855d682 100644 --- a/homeassistant/components/screenlogic/entity.py +++ b/homeassistant/components/screenlogic/entity.py @@ -44,7 +44,7 @@ class ScreenLogicEntityDescription( enabled_lambda: Callable[..., bool] | None = None -class ScreenlogicEntity(CoordinatorEntity[ScreenlogicDataUpdateCoordinator]): +class ScreenLogicEntity(CoordinatorEntity[ScreenlogicDataUpdateCoordinator]): """Base class for all ScreenLogic entities.""" entity_description: ScreenLogicEntityDescription @@ -118,7 +118,7 @@ class ScreenLogicPushEntityDescription( """Base class for a ScreenLogic push entity description.""" -class ScreenLogicPushEntity(ScreenlogicEntity): +class ScreenLogicPushEntity(ScreenLogicEntity): """Base class for all ScreenLogic push entities.""" entity_description: ScreenLogicPushEntityDescription @@ -157,8 +157,8 @@ class ScreenLogicPushEntity(ScreenlogicEntity): self._async_data_updated() -class ScreenLogicCircuitEntity(ScreenLogicPushEntity): - """Base class for all ScreenLogic switch and light entities.""" +class ScreenLogicSwitchingEntity(ScreenLogicEntity): + """Base class for all switchable entities.""" @property def is_on(self) -> bool: @@ -167,13 +167,20 @@ class ScreenLogicCircuitEntity(ScreenLogicPushEntity): async def async_turn_on(self, **kwargs: Any) -> None: """Send the ON command.""" - await self._async_set_circuit(ON_OFF.ON) + await self._async_set_state(ON_OFF.ON) async def async_turn_off(self, **kwargs: Any) -> None: """Send the OFF command.""" - await self._async_set_circuit(ON_OFF.OFF) + await self._async_set_state(ON_OFF.OFF) - async def _async_set_circuit(self, state: ON_OFF) -> None: + async def _async_set_state(self, state: ON_OFF) -> None: + raise NotImplementedError() + + +class ScreenLogicCircuitEntity(ScreenLogicSwitchingEntity, ScreenLogicPushEntity): + """Base class for all ScreenLogic circuit switch and light entities.""" + + async def _async_set_state(self, state: ON_OFF) -> None: try: await self.gateway.async_set_circuit(self._data_key, state.value) except (ScreenLogicCommunicationError, ScreenLogicError) as sle: diff --git a/homeassistant/components/screenlogic/number.py b/homeassistant/components/screenlogic/number.py index a275705f646..cc5efa6c7ad 100644 --- a/homeassistant/components/screenlogic/number.py +++ b/homeassistant/components/screenlogic/number.py @@ -21,7 +21,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN as SL_DOMAIN from .coordinator import ScreenlogicDataUpdateCoordinator -from .entity import ScreenlogicEntity, ScreenLogicEntityDescription +from .entity import ScreenLogicEntity, ScreenLogicEntityDescription from .util import cleanup_excluded_entity, get_ha_unit _LOGGER = logging.getLogger(__name__) @@ -87,7 +87,7 @@ async def async_setup_entry( async_add_entities(entities) -class ScreenLogicNumber(ScreenlogicEntity, NumberEntity): +class ScreenLogicNumber(ScreenLogicEntity, NumberEntity): """Class to represent a ScreenLogic Number entity.""" entity_description: ScreenLogicNumberDescription diff --git a/homeassistant/components/screenlogic/sensor.py b/homeassistant/components/screenlogic/sensor.py index 87bc101a074..c73ce8be42c 100644 --- a/homeassistant/components/screenlogic/sensor.py +++ b/homeassistant/components/screenlogic/sensor.py @@ -25,7 +25,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN as SL_DOMAIN from .coordinator import ScreenlogicDataUpdateCoordinator from .entity import ( - ScreenlogicEntity, + ScreenLogicEntity, ScreenLogicEntityDescription, ScreenLogicPushEntity, ScreenLogicPushEntityDescription, @@ -295,7 +295,7 @@ async def async_setup_entry( async_add_entities(entities) -class ScreenLogicSensor(ScreenlogicEntity, SensorEntity): +class ScreenLogicSensor(ScreenLogicEntity, SensorEntity): """Representation of a ScreenLogic sensor entity.""" entity_description: ScreenLogicSensorDescription diff --git a/homeassistant/components/screenlogic/switch.py b/homeassistant/components/screenlogic/switch.py index e64f7a3a164..43f749db913 100644 --- a/homeassistant/components/screenlogic/switch.py +++ b/homeassistant/components/screenlogic/switch.py @@ -13,18 +13,29 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import DOMAIN as SL_DOMAIN, LIGHT_CIRCUIT_FUNCTIONS from .coordinator import ScreenlogicDataUpdateCoordinator -from .entity import ScreenLogicCircuitEntity, ScreenLogicPushEntityDescription +from .entity import ( + ScreenLogicCircuitEntity, + ScreenLogicPushEntityDescription, + ScreenLogicSwitchingEntity, +) _LOGGER = logging.getLogger(__name__) +@dataclass(frozen=True) +class ScreenLogicCircuitSwitchDescription( + SwitchEntityDescription, ScreenLogicPushEntityDescription +): + """Describes a ScreenLogic switch entity.""" + + async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Set up entry.""" - entities: list[ScreenLogicSwitch] = [] + entities: list[ScreenLogicSwitchingEntity] = [] coordinator: ScreenlogicDataUpdateCoordinator = hass.data[SL_DOMAIN][ config_entry.entry_id ] @@ -39,9 +50,9 @@ async def async_setup_entry( circuit_name = circuit_data[ATTR.NAME] circuit_interface = INTERFACE(circuit_data[ATTR.INTERFACE]) entities.append( - ScreenLogicSwitch( + ScreenLogicCircuitSwitch( coordinator, - ScreenLogicSwitchDescription( + ScreenLogicCircuitSwitchDescription( subscription_code=CODE.STATUS_CHANGED, data_root=(DEVICE.CIRCUIT,), key=circuit_index, @@ -56,14 +67,7 @@ async def async_setup_entry( async_add_entities(entities) -@dataclass(frozen=True) -class ScreenLogicSwitchDescription( - SwitchEntityDescription, ScreenLogicPushEntityDescription -): - """Describes a ScreenLogic switch entity.""" - - -class ScreenLogicSwitch(ScreenLogicCircuitEntity, SwitchEntity): +class ScreenLogicCircuitSwitch(ScreenLogicCircuitEntity, SwitchEntity): """Class to represent a ScreenLogic Switch.""" - entity_description: ScreenLogicSwitchDescription + entity_description: ScreenLogicCircuitSwitchDescription