Add Screenlogic IntelliChem and SCG data (#49689)

This commit is contained in:
Kevin Worrel 2021-04-27 13:43:48 -07:00 committed by GitHub
parent 4b74c57285
commit 41c6474249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 175 additions and 22 deletions

View file

@ -132,10 +132,16 @@ class ScreenlogicDataUpdateCoordinator(DataUpdateCoordinator):
class ScreenlogicEntity(CoordinatorEntity): class ScreenlogicEntity(CoordinatorEntity):
"""Base class for all ScreenLogic entities.""" """Base class for all ScreenLogic entities."""
def __init__(self, coordinator, data_key): def __init__(self, coordinator, data_key, enabled=True):
"""Initialize of the entity.""" """Initialize of the entity."""
super().__init__(coordinator) super().__init__(coordinator)
self._data_key = data_key self._data_key = data_key
self._enabled_default = enabled
@property
def entity_registry_enabled_default(self):
"""Entity enabled by default."""
return self._enabled_default
@property @property
def mac(self): def mac(self):

View file

@ -1,7 +1,7 @@
"""Support for a ScreenLogic Binary Sensor.""" """Support for a ScreenLogic Binary Sensor."""
import logging import logging
from screenlogicpy.const import DATA as SL_DATA, DEVICE_TYPE, ON_OFF from screenlogicpy.const import DATA as SL_DATA, DEVICE_TYPE, EQUIPMENT, ON_OFF
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PROBLEM, DEVICE_CLASS_PROBLEM,
@ -24,6 +24,37 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
# Generic binary sensor # Generic binary sensor
entities.append(ScreenLogicBinarySensor(coordinator, "chem_alarm")) entities.append(ScreenLogicBinarySensor(coordinator, "chem_alarm"))
if (
coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"]
& EQUIPMENT.FLAG_INTELLICHEM
):
# IntelliChem alarm sensors
entities.extend(
[
ScreenlogicChemistryAlarmBinarySensor(coordinator, chem_alarm)
for chem_alarm in coordinator.data[SL_DATA.KEY_CHEMISTRY][
SL_DATA.KEY_ALERTS
]
]
)
# Intellichem notification sensors
entities.extend(
[
ScreenlogicChemistryNotificationBinarySensor(coordinator, chem_notif)
for chem_notif in coordinator.data[SL_DATA.KEY_CHEMISTRY][
SL_DATA.KEY_NOTIFICATIONS
]
]
)
if (
coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"]
& EQUIPMENT.FLAG_CHLORINATOR
):
# SCG binary sensor
entities.append(ScreenlogicSCGBinarySensor(coordinator, "scg_status"))
async_add_entities(entities) async_add_entities(entities)
@ -38,8 +69,8 @@ class ScreenLogicBinarySensor(ScreenlogicEntity, BinarySensorEntity):
@property @property
def device_class(self): def device_class(self):
"""Return the device class.""" """Return the device class."""
device_class = self.sensor.get("device_type") device_type = self.sensor.get("device_type")
return SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(device_class) return SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS.get(device_type)
@property @property
def is_on(self) -> bool: def is_on(self) -> bool:
@ -50,3 +81,34 @@ class ScreenLogicBinarySensor(ScreenlogicEntity, BinarySensorEntity):
def sensor(self): def sensor(self):
"""Shortcut to access the sensor data.""" """Shortcut to access the sensor data."""
return self.coordinator.data[SL_DATA.KEY_SENSORS][self._data_key] return self.coordinator.data[SL_DATA.KEY_SENSORS][self._data_key]
class ScreenlogicChemistryAlarmBinarySensor(ScreenLogicBinarySensor):
"""Representation of a ScreenLogic IntelliChem alarm binary sensor entity."""
@property
def sensor(self):
"""Shortcut to access the sensor data."""
return self.coordinator.data[SL_DATA.KEY_CHEMISTRY][SL_DATA.KEY_ALERTS][
self._data_key
]
class ScreenlogicChemistryNotificationBinarySensor(ScreenLogicBinarySensor):
"""Representation of a ScreenLogic IntelliChem notification binary sensor entity."""
@property
def sensor(self):
"""Shortcut to access the sensor data."""
return self.coordinator.data[SL_DATA.KEY_CHEMISTRY][SL_DATA.KEY_NOTIFICATIONS][
self._data_key
]
class ScreenlogicSCGBinarySensor(ScreenLogicBinarySensor):
"""Representation of a ScreenLogic SCG binary sensor entity."""
@property
def sensor(self):
"""Shortcut to access the sensor data."""
return self.coordinator.data[SL_DATA.KEY_SCG][self._data_key]

View file

@ -1,7 +1,12 @@
"""Support for a ScreenLogic Sensor.""" """Support for a ScreenLogic Sensor."""
import logging 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 ( from homeassistant.components.sensor import (
DEVICE_CLASS_POWER, DEVICE_CLASS_POWER,
@ -14,7 +19,32 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__) _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 = { SL_DEVICE_TYPE_TO_HA_DEVICE_CLASS = {
DEVICE_TYPE.TEMPERATURE: DEVICE_CLASS_TEMPERATURE, DEVICE_TYPE.TEMPERATURE: DEVICE_CLASS_TEMPERATURE,
@ -26,22 +56,45 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up entry.""" """Set up entry."""
entities = [] entities = []
coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"] coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"]
equipment_flags = coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"]
# Generic sensors # Generic sensors
for sensor in coordinator.data[SL_DATA.KEY_SENSORS]: for sensor_name, sensor_data in coordinator.data[SL_DATA.KEY_SENSORS].items():
if sensor == "chem_alarm": if sensor_name in ("chem_alarm", "salt_ppm"):
continue continue
if coordinator.data[SL_DATA.KEY_SENSORS][sensor]["value"] != 0: if sensor_data["value"] != 0:
entities.append(ScreenLogicSensor(coordinator, sensor)) entities.append(ScreenLogicSensor(coordinator, sensor_name))
# Pump sensors # Pump sensors
for pump in coordinator.data[SL_DATA.KEY_PUMPS]: for pump_num, pump_data in coordinator.data[SL_DATA.KEY_PUMPS].items():
if ( if pump_data["data"] != 0 and "currentWatts" in pump_data:
coordinator.data[SL_DATA.KEY_PUMPS][pump]["data"] != 0 entities.extend(
and "currentWatts" in coordinator.data[SL_DATA.KEY_PUMPS][pump] ScreenLogicPumpSensor(coordinator, pump_num, pump_key)
): for pump_key in pump_data
for pump_key in PUMP_SENSORS: if pump_key in SUPPORTED_PUMP_SENSORS
entities.append(ScreenLogicPumpSensor(coordinator, pump, pump_key)) )
# 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) async_add_entities(entities)
@ -80,9 +133,9 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity):
class ScreenLogicPumpSensor(ScreenLogicSensor): class ScreenLogicPumpSensor(ScreenLogicSensor):
"""Representation of a ScreenLogic pump sensor entity.""" """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.""" """Initialize of the pump sensor."""
super().__init__(coordinator, f"{key}_{pump}") super().__init__(coordinator, f"{key}_{pump}", enabled)
self._pump_id = pump self._pump_id = pump
self._key = key self._key = key
@ -90,3 +143,34 @@ class ScreenLogicPumpSensor(ScreenLogicSensor):
def sensor(self): def sensor(self):
"""Shortcut to access the pump sensor data.""" """Shortcut to access the pump sensor data."""
return self.coordinator.data[SL_DATA.KEY_PUMPS][self._pump_id][self._key] 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]

View file

@ -1,7 +1,7 @@
"""Support for a ScreenLogic 'circuit' switch.""" """Support for a ScreenLogic 'circuit' switch."""
import logging import logging
from screenlogicpy.const import DATA as SL_DATA, ON_OFF from screenlogicpy.const import DATA as SL_DATA, GENERIC_CIRCUIT_NAMES, ON_OFF
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
@ -16,8 +16,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities = [] entities = []
coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"] coordinator = hass.data[DOMAIN][config_entry.entry_id]["coordinator"]
for circuit in coordinator.data[SL_DATA.KEY_CIRCUITS]: for circuit_num, circuit in coordinator.data[SL_DATA.KEY_CIRCUITS].items():
entities.append(ScreenLogicSwitch(coordinator, circuit)) enabled = circuit["name"] not in GENERIC_CIRCUIT_NAMES
entities.append(ScreenLogicSwitch(coordinator, circuit_num, enabled))
async_add_entities(entities) async_add_entities(entities)