mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 07:17:12 +00:00
This fixes https://github.com/home-assistant/home-assistant/issues/8976 When no data was available the module crashes.
This commit is contained in:
parent
cc18b5af3d
commit
e76e9e0966
@ -127,7 +127,7 @@ class DHTSensor(Entity):
|
|||||||
humidity_offset = self.humidity_offset
|
humidity_offset = self.humidity_offset
|
||||||
data = self.dht_client.data
|
data = self.dht_client.data
|
||||||
|
|
||||||
if self.type == SENSOR_TEMPERATURE:
|
if self.type == SENSOR_TEMPERATURE and SENSOR_TEMPERATURE in data:
|
||||||
temperature = data[SENSOR_TEMPERATURE]
|
temperature = data[SENSOR_TEMPERATURE]
|
||||||
_LOGGER.debug("Temperature %.1f \u00b0C + offset %.1f",
|
_LOGGER.debug("Temperature %.1f \u00b0C + offset %.1f",
|
||||||
temperature, temperature_offset)
|
temperature, temperature_offset)
|
||||||
@ -135,7 +135,7 @@ class DHTSensor(Entity):
|
|||||||
self._state = round(temperature + temperature_offset, 1)
|
self._state = round(temperature + temperature_offset, 1)
|
||||||
if self.temp_unit == TEMP_FAHRENHEIT:
|
if self.temp_unit == TEMP_FAHRENHEIT:
|
||||||
self._state = round(celsius_to_fahrenheit(temperature), 1)
|
self._state = round(celsius_to_fahrenheit(temperature), 1)
|
||||||
elif self.type == SENSOR_HUMIDITY:
|
elif self.type == SENSOR_HUMIDITY and SENSOR_HUMIDITY in data:
|
||||||
humidity = data[SENSOR_HUMIDITY]
|
humidity = data[SENSOR_HUMIDITY]
|
||||||
_LOGGER.debug("Humidity %.1f%% + offset %.1f",
|
_LOGGER.debug("Humidity %.1f%% + offset %.1f",
|
||||||
humidity, humidity_offset)
|
humidity, humidity_offset)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user