mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Split out shared screenlogic switch code (#106344)
This commit is contained in:
parent
9066555feb
commit
f45f0b4327
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user