Fix iaqualink sensors (#36000)

* iaqualink: small sensor fixes

* Re-add device_class, fix type hints.
This commit is contained in:
Florent Thoumie 2020-05-22 23:53:10 -07:00 committed by GitHub
parent 0514960bda
commit 8b8aa198fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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]: