mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Test the temperature returned by RM2 (#6205)
* Test the temperature returned by RM2 * Validate fields via voluptuous * Fixed range for humidity
This commit is contained in:
parent
8aa3124aa6
commit
c7fcd98cad
@ -32,7 +32,7 @@ SENSOR_TYPES = {
|
||||
'air_quality': ['Air Quality', ' '],
|
||||
'humidity': ['Humidity', '%'],
|
||||
'light': ['Light', ' '],
|
||||
'noise': ['Noise', ' ']
|
||||
'noise': ['Noise', ' '],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
@ -110,6 +110,13 @@ class BroadlinkData(object):
|
||||
self.data = None
|
||||
self._device = broadlink.a1((ip_addr, 80), mac_addr)
|
||||
self._device.timeout = timeout
|
||||
self._schema = vol.Schema({
|
||||
vol.Optional('temperature'): vol.Range(min=-50, max=150),
|
||||
vol.Optional('humidity'): vol.Range(min=0, max=100),
|
||||
vol.Optional('light'): vol.Any(0, 1, 2, 3),
|
||||
vol.Optional('air_quality'): vol.Any(0, 1, 2, 3),
|
||||
vol.Optional('noise'): vol.Any(0, 1, 2),
|
||||
})
|
||||
self.update = Throttle(interval)(self._update)
|
||||
if not self._auth():
|
||||
_LOGGER.warning("Failed to connect to device.")
|
||||
@ -117,16 +124,15 @@ class BroadlinkData(object):
|
||||
def _update(self, retry=3):
|
||||
try:
|
||||
data = self._device.check_sensors_raw()
|
||||
if (data is not None and data.get('humidity', 0) <= 100 and
|
||||
data.get('light', 0) in [0, 1, 2, 3] and
|
||||
data.get('air_quality', 0) in [0, 1, 2, 3] and
|
||||
data.get('noise', 0) in [0, 1, 2]):
|
||||
self.data = data
|
||||
if data is not None:
|
||||
self.data = self._schema(data)
|
||||
return
|
||||
except socket.timeout as error:
|
||||
if retry < 1:
|
||||
_LOGGER.error(error)
|
||||
return
|
||||
except vol.Invalid:
|
||||
pass # Continue quietly if device returned malformed data
|
||||
if retry > 0 and self._auth():
|
||||
self._update(retry-1)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user