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
This commit is contained in:
parent
8329472c72
commit
c6f67a5203
1 changed files with 9 additions and 5 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue