From 258ca30bc0e2740f68435ace0ed9f3a400c5a6d9 Mon Sep 17 00:00:00 2001 From: Kevin Worrel <37058192+dieselrabbit@users.noreply.github.com> Date: Wed, 13 Apr 2022 13:43:17 -0700 Subject: [PATCH] Sensor updates (#69937) Co-authored-by: J. Nick Koston --- .../components/screenlogic/sensor.py | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/screenlogic/sensor.py b/homeassistant/components/screenlogic/sensor.py index 7b3c9b0c1f8..beab664f448 100644 --- a/homeassistant/components/screenlogic/sensor.py +++ b/homeassistant/components/screenlogic/sensor.py @@ -18,6 +18,16 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import ScreenlogicEntity from .const import DOMAIN +SUPPORTED_BASIC_SENSORS = ( + "air_temperature", + "saturation", +) + +SUPPORTED_BASIC_CHEM_SENSORS = ( + "orp", + "ph", +) + SUPPORTED_CHEM_SENSORS = ( "calcium_harness", "current_orp", @@ -27,11 +37,13 @@ SUPPORTED_CHEM_SENSORS = ( "orp_last_dose_time", "orp_last_dose_volume", "orp_setpoint", + "orp_supply_level", "ph_dosing_state", "ph_last_dose_time", "ph_last_dose_volume", "ph_probe_water_temp", "ph_setpoint", + "ph_supply_level", "salt_tds_ppm", "total_alkalinity", ) @@ -60,10 +72,17 @@ async def async_setup_entry( equipment_flags = coordinator.data[SL_DATA.KEY_CONFIG]["equipment_flags"] # Generic sensors - for sensor_name, sensor_data in coordinator.data[SL_DATA.KEY_SENSORS].items(): - if sensor_name in ("chem_alarm", "salt_ppm"): - continue - if sensor_data["value"] != 0: + for sensor_name in coordinator.data[SL_DATA.KEY_SENSORS]: + if sensor_name in SUPPORTED_BASIC_SENSORS: + entities.append(ScreenLogicSensor(coordinator, sensor_name)) + + # 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)) # Pump sensors @@ -136,8 +155,7 @@ class ScreenLogicSensor(ScreenlogicEntity, SensorEntity): @property def native_value(self): """State of the sensor.""" - value = self.sensor["value"] - return (value - 1) if "supply" in self._data_key else value + return self.sensor["value"] @property def sensor(self): @@ -174,7 +192,7 @@ class ScreenLogicChemistrySensor(ScreenLogicSensor): value = self.sensor["value"] if "dosing_state" in self._key: return CHEM_DOSING_STATE.NAME_FOR_NUM[value] - return value + return (value - 1) if "supply" in self._data_key else value @property def sensor(self):