1 """Base ScreenLogicEntity definitions."""
3 from collections.abc
import Callable
4 from dataclasses
import dataclass
5 from datetime
import datetime
9 from screenlogicpy
import ScreenLogicGateway
10 from screenlogicpy.const.common
import (
12 ScreenLogicCommunicationError,
15 from screenlogicpy.const.data
import ATTR
16 from screenlogicpy.const.msg
import CODE
25 from .const
import ScreenLogicDataPath
26 from .coordinator
import ScreenlogicDataUpdateCoordinator
27 from .util
import generate_unique_id
29 _LOGGER = logging.getLogger(__name__)
32 @dataclass(frozen=True, kw_only=True)
34 """Base class for a ScreenLogic entity description."""
36 data_root: ScreenLogicDataPath
37 enabled_lambda: Callable[..., bool] |
None =
None
41 """Base class for all ScreenLogic entities."""
43 entity_description: ScreenLogicEntityDescription
44 _attr_has_entity_name =
True
48 coordinator: ScreenlogicDataUpdateCoordinator,
49 entity_description: ScreenLogicEntityDescription,
51 """Initialize of the entity."""
57 self.
_attr_unique_id_attr_unique_id = f
"{mac}_{generate_unique_id(*self._data_path)}"
59 assert mac
is not None
61 connections={(dr.CONNECTION_NETWORK_MAC, mac)},
62 manufacturer=
"Pentair",
69 def mac(self) -> str | None:
71 assert self.coordinator.config_entry
is not None
72 return self.coordinator.config_entry.unique_id
76 """Return the gateway."""
77 return self.coordinator.gateway
80 """Refresh the data from the gateway."""
87 """Refresh from a timed called."""
92 """Shortcut to the data for this entity."""
95 except KeyError
as ke:
99 @dataclass(frozen=True, kw_only=True)
101 """Base class for a ScreenLogic push entity description."""
103 subscription_code: CODE
107 """Base class for all ScreenLogic push entities."""
109 entity_description: ScreenLogicPushEntityDescription
113 coordinator: ScreenlogicDataUpdateCoordinator,
114 entity_description: ScreenLogicPushEntityDescription,
116 """Initialize of the entity."""
117 super().
__init__(coordinator, entity_description)
123 """Handle data updates."""
125 self.async_write_ha_state()
128 """When entity is added to hass."""
130 self.async_on_remove(
139 """Handle updated data from the coordinator."""
146 """Base class for all switchable entities."""
150 """Get whether the switch is in on state."""
151 return self.
entity_dataentity_data[ATTR.VALUE] == ON_OFF.ON
154 """Send the ON command."""
158 """Send the OFF command."""
162 raise NotImplementedError
166 """Base class for all ScreenLogic circuit switch and light entities."""
171 except (ScreenLogicCommunicationError, ScreenLogicError)
as sle:
173 f
"Failed to set_circuit {self._data_key} {state.value}: {sle.msg}"
175 _LOGGER.debug(
"Set circuit %s %s", self.
_data_key_data_key, state.value)
None _async_set_state(self, ON_OFF state)
None _async_refresh_timed(self, datetime now)
None __init__(self, ScreenlogicDataUpdateCoordinator coordinator, ScreenLogicEntityDescription entity_description)
None _async_refresh(self)
ScreenLogicGateway gateway(self)
None _async_data_updated(self)
None async_added_to_hass(self)
None _handle_coordinator_update(self)
None __init__(self, ScreenlogicDataUpdateCoordinator coordinator, ScreenLogicPushEntityDescription entity_description)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None _async_set_state(self, ON_OFF state)
None async_request_refresh(self)