Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions homeassistant/components/sensor/dht.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,23 @@ def update(self):
data = self.dht_client.data

if self.type == SENSOR_TEMPERATURE:
temperature = data[SENSOR_TEMPERATURE]
try:
temperature = data[SENSOR_TEMPERATURE]
except KeyError:
_LOGGER.error("Error reading temperature data")
return
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks the situation when the returned data contains humidity data but no temperature data.

_LOGGER.debug("Temperature %.1f \u00b0C + offset %.1f",
temperature, temperature_offset)
if (temperature >= -20) and (temperature < 80):
self._state = round(temperature + temperature_offset, 1)
if self.temp_unit == TEMP_FAHRENHEIT:
self._state = round(celsius_to_fahrenheit(temperature), 1)
elif self.type == SENSOR_HUMIDITY:
humidity = data[SENSOR_HUMIDITY]
try:
humidity = data[SENSOR_HUMIDITY]
except KeyError:
_LOGGER.error("Error reading humidity data")
return
_LOGGER.debug("Humidity %.1f%% + offset %.1f",
humidity, humidity_offset)
if (humidity >= 0) and (humidity <= 100):
Expand Down