1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Support case of unknown/unavailable temperature/humidity (#29959)

* Support case of unknown/unavailable temperature/humidity

State is never None, just a string.

* Lint suggestion
This commit is contained in:
Joakim Plate
2019-12-16 08:04:59 +01:00
committed by Paulus Schoutsen
parent 445fd15f76
commit 039cc98278
2 changed files with 33 additions and 8 deletions

View File

@@ -44,6 +44,7 @@ from homeassistant.const import (
STATE_LOCKED,
STATE_OFF,
STATE_ON,
STATE_UNAVAILABLE,
STATE_UNKNOWN,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
@@ -666,7 +667,7 @@ class TemperatureSettingTrait(_Trait):
device_class = attrs.get(ATTR_DEVICE_CLASS)
if device_class == sensor.DEVICE_CLASS_TEMPERATURE:
current_temp = self.state.state
if current_temp is not None:
if current_temp not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
response["thermostatTemperatureAmbient"] = round(
temp_util.convert(float(current_temp), unit, TEMP_CELSIUS), 1
)
@@ -887,7 +888,7 @@ class HumiditySettingTrait(_Trait):
device_class = attrs.get(ATTR_DEVICE_CLASS)
if device_class == sensor.DEVICE_CLASS_HUMIDITY:
current_humidity = self.state.state
if current_humidity is not None:
if current_humidity not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
response["humidityAmbientPercent"] = round(float(current_humidity))
return response