Test the temperature returned by RM2 (#6205)
* Test the temperature returned by RM2 * Validate fields via voluptuous * Fixed range for humiditypull/5526/merge
parent
8aa3124aa6
commit
c7fcd98cad
|
@ -32,7 +32,7 @@ SENSOR_TYPES = {
|
||||||
'air_quality': ['Air Quality', ' '],
|
'air_quality': ['Air Quality', ' '],
|
||||||
'humidity': ['Humidity', '%'],
|
'humidity': ['Humidity', '%'],
|
||||||
'light': ['Light', ' '],
|
'light': ['Light', ' '],
|
||||||
'noise': ['Noise', ' ']
|
'noise': ['Noise', ' '],
|
||||||
}
|
}
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
@ -110,6 +110,13 @@ class BroadlinkData(object):
|
||||||
self.data = None
|
self.data = None
|
||||||
self._device = broadlink.a1((ip_addr, 80), mac_addr)
|
self._device = broadlink.a1((ip_addr, 80), mac_addr)
|
||||||
self._device.timeout = timeout
|
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)
|
self.update = Throttle(interval)(self._update)
|
||||||
if not self._auth():
|
if not self._auth():
|
||||||
_LOGGER.warning("Failed to connect to device.")
|
_LOGGER.warning("Failed to connect to device.")
|
||||||
|
@ -117,16 +124,15 @@ class BroadlinkData(object):
|
||||||
def _update(self, retry=3):
|
def _update(self, retry=3):
|
||||||
try:
|
try:
|
||||||
data = self._device.check_sensors_raw()
|
data = self._device.check_sensors_raw()
|
||||||
if (data is not None and data.get('humidity', 0) <= 100 and
|
if data is not None:
|
||||||
data.get('light', 0) in [0, 1, 2, 3] and
|
self.data = self._schema(data)
|
||||||
data.get('air_quality', 0) in [0, 1, 2, 3] and
|
|
||||||
data.get('noise', 0) in [0, 1, 2]):
|
|
||||||
self.data = data
|
|
||||||
return
|
return
|
||||||
except socket.timeout as error:
|
except socket.timeout as error:
|
||||||
if retry < 1:
|
if retry < 1:
|
||||||
_LOGGER.error(error)
|
_LOGGER.error(error)
|
||||||
return
|
return
|
||||||
|
except vol.Invalid:
|
||||||
|
pass # Continue quietly if device returned malformed data
|
||||||
if retry > 0 and self._auth():
|
if retry > 0 and self._auth():
|
||||||
self._update(retry-1)
|
self._update(retry-1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue