1 """Support for a ScreenLogic Binary Sensor."""
6 from screenlogicpy.const.common
import ON_OFF
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 BINARY_SENSOR_DOMAIN,
13 BinarySensorDeviceClass,
15 BinarySensorEntityDescription,
21 from .coordinator
import ScreenlogicDataUpdateCoordinator
24 ScreenLogicEntityDescription,
25 ScreenLogicPushEntity,
26 ScreenLogicPushEntityDescription,
28 from .types
import ScreenLogicConfigEntry
29 from .util
import cleanup_excluded_entity
32 @dataclasses.dataclass(frozen=True, kw_only=True)
34 BinarySensorEntityDescription, ScreenLogicEntityDescription
36 """A class that describes ScreenLogic binary sensor eneites."""
39 @dataclasses.dataclass(frozen=True, kw_only=True)
41 ScreenLogicBinarySensorDescription, ScreenLogicPushEntityDescription
43 """Describes a ScreenLogicPushBinarySensor."""
46 SUPPORTED_CORE_SENSORS = [
48 subscription_code=CODE.STATUS_CHANGED,
49 data_root=(DEVICE.CONTROLLER, GROUP.SENSOR),
50 key=VALUE.ACTIVE_ALERT,
51 device_class=BinarySensorDeviceClass.PROBLEM,
54 subscription_code=CODE.STATUS_CHANGED,
55 data_root=(DEVICE.CONTROLLER, GROUP.SENSOR),
56 key=VALUE.CLEANER_DELAY,
59 subscription_code=CODE.STATUS_CHANGED,
60 data_root=(DEVICE.CONTROLLER, GROUP.SENSOR),
61 key=VALUE.FREEZE_MODE,
64 subscription_code=CODE.STATUS_CHANGED,
65 data_root=(DEVICE.CONTROLLER, GROUP.SENSOR),
69 subscription_code=CODE.STATUS_CHANGED,
70 data_root=(DEVICE.CONTROLLER, GROUP.SENSOR),
75 SUPPORTED_PUMP_SENSORS = [
77 data_root=(DEVICE.PUMP,),
82 SUPPORTED_INTELLICHEM_SENSORS = [
84 subscription_code=CODE.CHEMISTRY_CHANGED,
85 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
87 device_class=BinarySensorDeviceClass.PROBLEM,
90 subscription_code=CODE.CHEMISTRY_CHANGED,
91 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
92 key=VALUE.ORP_HIGH_ALARM,
93 device_class=BinarySensorDeviceClass.PROBLEM,
96 subscription_code=CODE.CHEMISTRY_CHANGED,
97 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
98 key=VALUE.ORP_LOW_ALARM,
99 device_class=BinarySensorDeviceClass.PROBLEM,
102 subscription_code=CODE.CHEMISTRY_CHANGED,
103 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
104 key=VALUE.ORP_SUPPLY_ALARM,
105 device_class=BinarySensorDeviceClass.PROBLEM,
108 subscription_code=CODE.CHEMISTRY_CHANGED,
109 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
110 key=VALUE.PH_HIGH_ALARM,
111 device_class=BinarySensorDeviceClass.PROBLEM,
114 subscription_code=CODE.CHEMISTRY_CHANGED,
115 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
116 key=VALUE.PH_LOW_ALARM,
117 device_class=BinarySensorDeviceClass.PROBLEM,
120 subscription_code=CODE.CHEMISTRY_CHANGED,
121 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
122 key=VALUE.PH_SUPPLY_ALARM,
123 device_class=BinarySensorDeviceClass.PROBLEM,
126 subscription_code=CODE.CHEMISTRY_CHANGED,
127 data_root=(DEVICE.INTELLICHEM, GROUP.ALARM),
128 key=VALUE.PROBE_FAULT_ALARM,
129 device_class=BinarySensorDeviceClass.PROBLEM,
132 subscription_code=CODE.CHEMISTRY_CHANGED,
133 data_root=(DEVICE.INTELLICHEM, GROUP.ALERT),
137 subscription_code=CODE.CHEMISTRY_CHANGED,
138 data_root=(DEVICE.INTELLICHEM, GROUP.ALERT),
142 subscription_code=CODE.CHEMISTRY_CHANGED,
143 data_root=(DEVICE.INTELLICHEM, GROUP.ALERT),
144 key=VALUE.PH_LOCKOUT,
147 subscription_code=CODE.CHEMISTRY_CHANGED,
148 data_root=(DEVICE.INTELLICHEM, GROUP.WATER_BALANCE),
150 device_class=BinarySensorDeviceClass.PROBLEM,
153 subscription_code=CODE.CHEMISTRY_CHANGED,
154 data_root=(DEVICE.INTELLICHEM, GROUP.WATER_BALANCE),
156 device_class=BinarySensorDeviceClass.PROBLEM,
160 SUPPORTED_SCG_SENSORS = [
162 data_root=(DEVICE.SCG, GROUP.SENSOR),
170 config_entry: ScreenLogicConfigEntry,
171 async_add_entities: AddEntitiesCallback,
174 coordinator = config_entry.runtime_data
175 gateway = coordinator.gateway
177 entities: list[ScreenLogicBinarySensor] = [
179 for core_sensor_description
in SUPPORTED_CORE_SENSORS
182 *core_sensor_description.data_root, core_sensor_description.key
188 for p_index, p_data
in gateway.get_data(DEVICE.PUMP).items():
189 if not p_data
or not p_data.get(VALUE.DATA):
193 coordinator, copy(proto_pump_sensor_description), p_index
195 for proto_pump_sensor_description
in SUPPORTED_PUMP_SENSORS
198 chem_sensor_description: ScreenLogicPushBinarySensorDescription
199 for chem_sensor_description
in SUPPORTED_INTELLICHEM_SENSORS:
200 chem_sensor_data_path = (
201 *chem_sensor_description.data_root,
202 chem_sensor_description.key,
204 if EQUIPMENT_FLAG.INTELLICHEM
not in gateway.equipment_flags:
206 coordinator, BINARY_SENSOR_DOMAIN, chem_sensor_data_path
209 if gateway.get_data(*chem_sensor_data_path):
214 scg_sensor_description: ScreenLogicBinarySensorDescription
215 for scg_sensor_description
in SUPPORTED_SCG_SENSORS:
216 scg_sensor_data_path = (
217 *scg_sensor_description.data_root,
218 scg_sensor_description.key,
220 if EQUIPMENT_FLAG.CHLORINATOR
not in gateway.equipment_flags:
222 coordinator, BINARY_SENSOR_DOMAIN, scg_sensor_data_path
225 if gateway.get_data(*scg_sensor_data_path):
234 """Representation of a ScreenLogic binary sensor entity."""
236 entity_description: ScreenLogicBinarySensorDescription
237 _attr_has_entity_name =
True
238 _attr_entity_category = EntityCategory.DIAGNOSTIC
242 """Determine if the sensor is on."""
243 return self.
entity_dataentity_data[ATTR.VALUE] == ON_OFF.ON
247 """Representation of a ScreenLogic push binary sensor entity."""
249 entity_description: ScreenLogicPushBinarySensorDescription
253 """Representation of a ScreenLogic binary sensor entity for pump data."""
257 coordinator: ScreenlogicDataUpdateCoordinator,
258 entity_description: ScreenLogicBinarySensorDescription,
261 """Initialize of the entity."""
262 entity_description = dataclasses.replace(
263 entity_description, data_root=(DEVICE.PUMP, pump_index)
265 super().
__init__(coordinator, entity_description)
None __init__(self, ScreenlogicDataUpdateCoordinator coordinator, ScreenLogicBinarySensorDescription entity_description, int pump_index)
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)