Sensor updates (#69937)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Kevin Worrel 2022-04-13 13:43:17 -07:00 committed by GitHub
parent c7b5d7107f
commit 258ca30bc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,16 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import ScreenlogicEntity from . import ScreenlogicEntity
from .const import DOMAIN from .const import DOMAIN
SUPPORTED_BASIC_SENSORS = (
"air_temperature",
"saturation",
)
SUPPORTED_BASIC_CHEM_SENSORS = (
"orp",
"ph",
)
SUPPORTED_CHEM_SENSORS = ( SUPPORTED_CHEM_SENSORS = (
"calcium_harness", "calcium_harness",
"current_orp", "current_orp",
@ -27,11 +37,13 @@ SUPPORTED_CHEM_SENSORS = (
"orp_last_dose_time", "orp_last_dose_time",
"orp_last_dose_volume", "orp_last_dose_volume",
"orp_setpoint", "orp_setpoint",
"orp_supply_level",
"ph_dosing_state", "ph_dosing_state",
"ph_last_dose_time", "ph_last_dose_time",
"ph_last_dose_volume", "ph_last_dose_volume",
"ph_probe_water_temp", "ph_probe_water_temp",
"ph_setpoint", "ph_setpoint",
"ph_supply_level",
"salt_tds_ppm", "salt_tds_ppm",
"total_alkalinity", "total_alkalinity",
) )
@ -60,10 +72,17 @@ async def async_setup_entry(
equipment_flags = coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"] equipment_flags = coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"]
# Generic sensors # Generic sensors
for sensor_name, sensor_data in coordinator.data[SL_DATA.KEY_SENSORS].items(): for sensor_name in coordinator.data[SL_DATA.KEY_SENSORS]:
if sensor_name in ("chem_alarm", "salt_ppm"): if sensor_name in SUPPORTED_BASIC_SENSORS:
continue entities.append(ScreenLogicSensor(coordinator, sensor_name))
if sensor_data["value"] != 0:
# While these values exist in the chemistry data, their last value doesn't
# persist there when the pump is off/there is no flow. Pulling them from
# the basic sensors keeps the 'last' value and is better for graphs.
if (
equipment_flags & EQUIPMENT.FLAG_INTELLICHEM
and sensor_name in SUPPORTED_BASIC_CHEM_SENSORS
):
entities.append(ScreenLogicSensor(coordinator, sensor_name)) entities.append(ScreenLogicSensor(coordinator, sensor_name))
# Pump sensors # Pump sensors
@ -136,8 +155,7 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity):
@property @property
def native_value(self): def native_value(self):
"""State of the sensor.""" """State of the sensor."""
value = self.sensor["value"] return self.sensor["value"]
return (value - 1) if "supply" in self._data_key else value
@property @property
def sensor(self): def sensor(self):
@ -174,7 +192,7 @@ class ScreenLogicChemistrySensor(ScreenLogicSensor):
value = self.sensor["value"] value = self.sensor["value"]
if "dosing_state" in self._key: if "dosing_state" in self._key:
return CHEM_DOSING_STATE.NAME_FOR_NUM[value] return CHEM_DOSING_STATE.NAME_FOR_NUM[value]
return value return (value - 1) if "supply" in self._data_key else value
@property @property
def sensor(self): def sensor(self):