From 8b8aa198faeff3060d13f7d851b8b920557ec48e Mon Sep 17 00:00:00 2001 From: Florent Thoumie Date: Fri, 22 May 2020 23:53:10 -0700 Subject: [PATCH] Fix iaqualink sensors (#36000) * iaqualink: small sensor fixes * Re-add device_class, fix type hints. --- homeassistant/components/iaqualink/sensor.py | 21 ++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/iaqualink/sensor.py b/homeassistant/components/iaqualink/sensor.py index 81021d0b447..80f18dc8191 100644 --- a/homeassistant/components/iaqualink/sensor.py +++ b/homeassistant/components/iaqualink/sensor.py @@ -34,16 +34,25 @@ class HassAqualinkSensor(AqualinkEntity): return self.dev.label @property - def unit_of_measurement(self) -> str: + def unit_of_measurement(self) -> Optional[str]: """Return the measurement unit for the sensor.""" - if self.dev.system.temp_unit == "F": - return TEMP_FAHRENHEIT - return TEMP_CELSIUS + if self.dev.name.endswith("_temp"): + if self.dev.system.temp_unit == "F": + return TEMP_FAHRENHEIT + return TEMP_CELSIUS + return None @property - def state(self) -> str: + def state(self) -> Optional[str]: """Return the state of the sensor.""" - return int(self.dev.state) if self.dev.state != "" else None + if self.dev.state == "": + return None + + try: + state = int(self.dev.state) + except ValueError: + state = float(self.dev.state) + return state @property def device_class(self) -> Optional[str]: