Implemented range checking for temperature and humidity. Out-of-range… (#2805)

* Implemented range checking for temperature and humidity. Out-of-range values will be ignored

* Removed unused import

* Use celsius_to_fahrenheit conversion method
pull/2818/head
Open Home Automation 2016-08-14 10:02:26 +02:00 committed by Paulus Schoutsen
parent 8329472c72
commit c6f67a5203
1 changed files with 9 additions and 5 deletions

View File

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