1 """Support for a ScreenLogic number entity."""
3 from dataclasses
import dataclass
6 from screenlogicpy.const.common
import ScreenLogicCommunicationError, ScreenLogicError
7 from screenlogicpy.const.data
import ATTR, DEVICE, GROUP, VALUE
8 from screenlogicpy.const.msg
import CODE
9 from screenlogicpy.device_const.system
import EQUIPMENT_FLAG
12 DOMAIN
as NUMBER_DOMAIN,
14 NumberEntityDescription,
22 from .coordinator
import ScreenlogicDataUpdateCoordinator
25 ScreenLogicEntityDescription,
26 ScreenLogicPushEntity,
27 ScreenLogicPushEntityDescription,
29 from .types
import ScreenLogicConfigEntry
30 from .util
import cleanup_excluded_entity, get_ha_unit
32 _LOGGER = logging.getLogger(__name__)
37 @dataclass(frozen=True, kw_only=True)
39 NumberEntityDescription,
40 ScreenLogicEntityDescription,
42 """Describes a ScreenLogic number entity."""
45 @dataclass(frozen=True, kw_only=True)
47 ScreenLogicNumberDescription,
48 ScreenLogicPushEntityDescription,
50 """Describes a ScreenLogic push number entity."""
53 SUPPORTED_INTELLICHEM_NUMBERS = [
55 subscription_code=CODE.CHEMISTRY_CHANGED,
56 data_root=(DEVICE.INTELLICHEM, GROUP.CONFIGURATION),
57 key=VALUE.CALCIUM_HARDNESS,
58 entity_category=EntityCategory.CONFIG,
62 subscription_code=CODE.CHEMISTRY_CHANGED,
63 data_root=(DEVICE.INTELLICHEM, GROUP.CONFIGURATION),
65 entity_category=EntityCategory.CONFIG,
69 subscription_code=CODE.CHEMISTRY_CHANGED,
70 data_root=(DEVICE.INTELLICHEM, GROUP.CONFIGURATION),
71 key=VALUE.TOTAL_ALKALINITY,
72 entity_category=EntityCategory.CONFIG,
76 subscription_code=CODE.CHEMISTRY_CHANGED,
77 data_root=(DEVICE.INTELLICHEM, GROUP.CONFIGURATION),
78 key=VALUE.SALT_TDS_PPM,
79 entity_category=EntityCategory.CONFIG,
84 SUPPORTED_SCG_NUMBERS = [
86 data_root=(DEVICE.SCG, GROUP.CONFIGURATION),
87 key=VALUE.POOL_SETPOINT,
88 entity_category=EntityCategory.CONFIG,
91 data_root=(DEVICE.SCG, GROUP.CONFIGURATION),
92 key=VALUE.SPA_SETPOINT,
93 entity_category=EntityCategory.CONFIG,
100 config_entry: ScreenLogicConfigEntry,
101 async_add_entities: AddEntitiesCallback,
104 entities: list[ScreenLogicNumber] = []
105 coordinator = config_entry.runtime_data
106 gateway = coordinator.gateway
108 for chem_number_description
in SUPPORTED_INTELLICHEM_NUMBERS:
109 chem_number_data_path = (
110 *chem_number_description.data_root,
111 chem_number_description.key,
113 if EQUIPMENT_FLAG.INTELLICHEM
not in gateway.equipment_flags:
116 if gateway.get_data(*chem_number_data_path):
121 for scg_number_description
in SUPPORTED_SCG_NUMBERS:
122 scg_number_data_path = (
123 *scg_number_description.data_root,
124 scg_number_description.key,
126 if EQUIPMENT_FLAG.CHLORINATOR
not in gateway.equipment_flags:
129 if gateway.get_data(*scg_number_data_path):
136 """Base class to represent a ScreenLogic Number entity."""
138 entity_description: ScreenLogicNumberDescription
142 coordinator: ScreenlogicDataUpdateCoordinator,
143 entity_description: ScreenLogicNumberDescription,
145 """Initialize a ScreenLogic number entity."""
146 super().
__init__(coordinator, entity_description)
151 if entity_description.native_max_value
is None and isinstance(
152 max_val := self.
entity_dataentity_data.
get(ATTR.MAX_SETPOINT), int | float
155 if entity_description.native_min_value
is None and isinstance(
156 min_val := self.
entity_dataentity_data.
get(ATTR.MIN_SETPOINT), int | float
159 if entity_description.native_step
is None and isinstance(
166 """Return the current value."""
170 """Update the current value."""
171 raise NotImplementedError
175 """Base class to preresent a ScreenLogic Push Number entity."""
177 entity_description: ScreenLogicPushNumberDescription
181 """Class to represent a ScreenLogic Chemistry Number entity."""
184 """Update the current value."""
191 except (ScreenLogicCommunicationError, ScreenLogicError)
as sle:
193 f
"Failed to set '{self._data_key}' to {value}: {sle.msg}"
195 _LOGGER.debug(
"Set '%s' to %s", self.
_data_key_data_key, value)
200 """Class to represent a ScreenLoigic SCG Number entity."""
203 """Update the current value."""
210 except (ScreenLogicCommunicationError, ScreenLogicError)
as sle:
212 f
"Failed to set '{self._data_key}' to {value}: {sle.msg}"
214 _LOGGER.debug(
"Set '%s' to %s", self.
_data_key_data_key, value)
None _async_refresh(self)
ScreenLogicGateway gateway(self)
None async_set_native_value(self, float value)
None __init__(self, ScreenlogicDataUpdateCoordinator coordinator, ScreenLogicNumberDescription entity_description)
None async_set_native_value(self, float value)
_attr_native_unit_of_measurement
None async_set_native_value(self, float value)
None _async_refresh(self, bool log_failures=True, bool raise_on_auth_failed=False, bool scheduled=False, bool raise_on_entry_error=False)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ScreenLogicConfigEntry config_entry, AddEntitiesCallback async_add_entities)
None cleanup_excluded_entity(ScreenlogicDataUpdateCoordinator coordinator, str platform_domain, ScreenLogicDataPath data_path)