From c6f67a52038c73d689f888ae72203dc0f6f595d5 Mon Sep 17 00:00:00 2001 From: Open Home Automation Date: Sun, 14 Aug 2016 10:02:26 +0200 Subject: [PATCH] =?UTF-8?q?Implemented=20range=20checking=20for=20temperat?= =?UTF-8?q?ure=20and=20humidity.=20Out-of-range=E2=80=A6=20(#2805)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Implemented range checking for temperature and humidity. Out-of-range values will be ignored * Removed unused import * Use celsius_to_fahrenheit conversion method --- homeassistant/components/sensor/dht.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/sensor/dht.py b/homeassistant/components/sensor/dht.py index ec33b1e4042..170c63a2620 100644 --- a/homeassistant/components/sensor/dht.py +++ b/homeassistant/components/sensor/dht.py @@ -102,12 +102,16 @@ class DHTSensor(Entity): data = self.dht_client.data if self.type == 'temperature': - self._state = round(data['temperature'], 1) - if self.temp_unit == TEMP_FAHRENHEIT: - self._state = round(celsius_to_fahrenheit(data['temperature']), - 1) + temperature = round(data['temperature'], 1) + if (temperature >= -20) and (temperature < 80): + self._state = temperature + if self.temp_unit == TEMP_FAHRENHEIT: + self._state = round(celsius_to_fahrenheit(temperature), + 1) elif self.type == 'humidity': - self._state = round(data['humidity'], 1) + humidity = round(data['humidity'], 1) + if (humidity >= 0) and (humidity <= 100): + self._state = humidity class DHTClient(object):