forked from platypush/platypush
Better management of sensor tolerance in SensorBackend
This commit is contained in:
parent
851635bc15
commit
e0351421ad
1 changed files with 13 additions and 3 deletions
|
@ -64,7 +64,7 @@ class SensorBackend(Backend):
|
||||||
self.plugin = plugin
|
self.plugin = plugin
|
||||||
self.plugin_args = plugin_args or {}
|
self.plugin_args = plugin_args or {}
|
||||||
self.thresholds = thresholds
|
self.thresholds = thresholds
|
||||||
self.tolerance = tolerance or {}
|
self.tolerance = tolerance
|
||||||
self.poll_seconds = poll_seconds
|
self.poll_seconds = poll_seconds
|
||||||
|
|
||||||
if isinstance(enabled_sensors, list):
|
if isinstance(enabled_sensors, list):
|
||||||
|
@ -115,8 +115,11 @@ class SensorBackend(Backend):
|
||||||
ret[k] = v
|
ret[k] = v
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if v is None:
|
||||||
|
continue
|
||||||
|
|
||||||
if isinstance(self.tolerance, dict):
|
if isinstance(self.tolerance, dict):
|
||||||
tolerance = self.tolerance.get(k, self.default_tolerance)
|
tolerance = float(self.tolerance.get(k, self.default_tolerance))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
tolerance = float(self.tolerance)
|
tolerance = float(self.tolerance)
|
||||||
|
@ -165,6 +168,13 @@ class SensorBackend(Backend):
|
||||||
if data_above_threshold:
|
if data_above_threshold:
|
||||||
self.bus.post(SensorDataAboveThresholdEvent(data=data_above_threshold))
|
self.bus.post(SensorDataAboveThresholdEvent(data=data_above_threshold))
|
||||||
|
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
if new_data:
|
||||||
|
if isinstance(new_data, dict):
|
||||||
|
for k, v in new_data.items():
|
||||||
|
self.data[k] = v
|
||||||
|
else:
|
||||||
self.data = new_data
|
self.data = new_data
|
||||||
|
|
||||||
if self.poll_seconds:
|
if self.poll_seconds:
|
||||||
|
|
Loading…
Reference in a new issue