Add Screenlogic IntelliChem and SCG data (#49689)
This commit is contained in:
parent
4b74c57285
commit
41c6474249
4 changed files with 175 additions and 22 deletions
|
@ -1,7 +1,12 @@
|
|||
"""Support for a ScreenLogic Sensor."""
|
||||
import logging
|
||||
|
||||
from screenlogicpy.const import DATA as SL_DATA, DEVICE_TYPE
|
||||
from screenlogicpy.const import (
|
||||
CHEM_DOSING_STATE,
|
||||
DATA as SL_DATA,
|
||||
DEVICE_TYPE,
|
||||
EQUIPMENT,
|
||||
)
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
DEVICE_CLASS_POWER,
|
||||
|
@ -14,7 +19,32 @@ from .const import DOMAIN
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PUMP_SENSORS = ("currentWatts", "currentRPM", "currentGPM")
|
||||
SUPPORTED_CHEM_SENSORS = (
|
||||
"calcium_harness",
|
||||
"current_orp",
|
||||
"current_ph",
|
||||
"cya",
|
||||
"orp_dosing_state",
|
||||
"orp_last_dose_time",
|
||||
"orp_last_dose_volume",
|
||||
"orp_setpoint",
|
||||
"ph_dosing_state",
|
||||
"ph_last_dose_time",
|
||||
"ph_last_dose_volume",
|
||||
"ph_probe_water_temp",
|
||||
"ph_setpoint",
|
||||
"salt_tds_ppm",
|
||||
"total_alkalinity",
|
||||
)
|
||||
|
||||
SUPPORTED_SCG_SENSORS = (
|
||||
"scg_level1",
|
||||
"scg_level2",
|
||||
"scg_salt_ppm",
|
||||
"scg_super_chlor_timer",
|
||||
)
|
||||
|
||||
SUPPORTED_PUMP_SENSORS = ("currentWatts", "currentRPM", "currentGPM")
|
||||
|
||||
SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS = {
|
||||
DEVICE_TYPE.TEMPERATURE: DEVICE_CLASS_TEMPERATURE,
|
||||
|
@ -26,22 +56,45 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
"""Set up entry."""
|
||||
entities = []
|
||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"]
|
||||
equipment_flags = coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"]
|
||||
|
||||
# Generic sensors
|
||||
for sensor in coordinator.data[SL_DATA.KEY_SENSORS]:
|
||||
if sensor == "chem_alarm":
|
||||
for sensor_name, sensor_data in coordinator.data[SL_DATA.KEY_SENSORS].items():
|
||||
if sensor_name in ("chem_alarm", "salt_ppm"):
|
||||
continue
|
||||
if coordinator.data[SL_DATA.KEY_SENSORS][sensor]["value"] != 0:
|
||||
entities.append(ScreenLogicSensor(coordinator, sensor))
|
||||
if sensor_data["value"] != 0:
|
||||
entities.append(ScreenLogicSensor(coordinator, sensor_name))
|
||||
|
||||
# Pump sensors
|
||||
for pump in coordinator.data[SL_DATA.KEY_PUMPS]:
|
||||
if (
|
||||
coordinator.data[SL_DATA.KEY_PUMPS][pump]["data"] != 0
|
||||
and "currentWatts" in coordinator.data[SL_DATA.KEY_PUMPS][pump]
|
||||
):
|
||||
for pump_key in PUMP_SENSORS:
|
||||
entities.append(ScreenLogicPumpSensor(coordinator, pump, pump_key))
|
||||
for pump_num, pump_data in coordinator.data[SL_DATA.KEY_PUMPS].items():
|
||||
if pump_data["data"] != 0 and "currentWatts" in pump_data:
|
||||
entities.extend(
|
||||
ScreenLogicPumpSensor(coordinator, pump_num, pump_key)
|
||||
for pump_key in pump_data
|
||||
if pump_key in SUPPORTED_PUMP_SENSORS
|
||||
)
|
||||
|
||||
# IntelliChem sensors
|
||||
if equipment_flags & EQUIPMENT.FLAG_INTELLICHEM:
|
||||
for chem_sensor_name in coordinator.data[SL_DATA.KEY_CHEMISTRY]:
|
||||
enabled = True
|
||||
if equipment_flags & EQUIPMENT.FLAG_CHLORINATOR:
|
||||
if chem_sensor_name in ("salt_tds_ppm"):
|
||||
enabled = False
|
||||
if chem_sensor_name in SUPPORTED_CHEM_SENSORS:
|
||||
entities.append(
|
||||
ScreenLogicChemistrySensor(coordinator, chem_sensor_name, enabled)
|
||||
)
|
||||
|
||||
# SCG sensors
|
||||
if equipment_flags & EQUIPMENT.FLAG_CHLORINATOR:
|
||||
entities.extend(
|
||||
[
|
||||
ScreenLogicSCGSensor(coordinator, scg_sensor)
|
||||
for scg_sensor in coordinator.data[SL_DATA.KEY_SCG]
|
||||
if scg_sensor in SUPPORTED_SCG_SENSORS
|
||||
]
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -80,9 +133,9 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity):
|
|||
class ScreenLogicPumpSensor(ScreenLogicSensor):
|
||||
"""Representation of a ScreenLogic pump sensor entity."""
|
||||
|
||||
def __init__(self, coordinator, pump, key):
|
||||
def __init__(self, coordinator, pump, key, enabled=True):
|
||||
"""Initialize of the pump sensor."""
|
||||
super().__init__(coordinator, f"{key}_{pump}")
|
||||
super().__init__(coordinator, f"{key}_{pump}", enabled)
|
||||
self._pump_id = pump
|
||||
self._key = key
|
||||
|
||||
|
@ -90,3 +143,34 @@ class ScreenLogicPumpSensor(ScreenLogicSensor):
|
|||
def sensor(self):
|
||||
"""Shortcut to access the pump sensor data."""
|
||||
return self.coordinator.data[SL_DATA.KEY_PUMPS][self._pump_id][self._key]
|
||||
|
||||
|
||||
class ScreenLogicChemistrySensor(ScreenLogicSensor):
|
||||
"""Representation of a ScreenLogic IntelliChem sensor entity."""
|
||||
|
||||
def __init__(self, coordinator, key, enabled=True):
|
||||
"""Initialize of the pump sensor."""
|
||||
super().__init__(coordinator, f"chem_{key}", enabled)
|
||||
self._key = key
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""State of the sensor."""
|
||||
value = self.sensor["value"]
|
||||
if "dosing_state" in self._key:
|
||||
return CHEM_DOSING_STATE.NAME_FOR_NUM[value]
|
||||
return value
|
||||
|
||||
@property
|
||||
def sensor(self):
|
||||
"""Shortcut to access the pump sensor data."""
|
||||
return self.coordinator.data[SL_DATA.KEY_CHEMISTRY][self._key]
|
||||
|
||||
|
||||
class ScreenLogicSCGSensor(ScreenLogicSensor):
|
||||
"""Representation of ScreenLogic SCG sensor entity."""
|
||||
|
||||
@property
|
||||
def sensor(self):
|
||||
"""Shortcut to access the pump sensor data."""
|
||||
return self.coordinator.data[SL_DATA.KEY_SCG][self._data_key]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue