Support for multiple thresholds for the same sensor
This commit is contained in:
parent
2df9c5a890
commit
6e867e9fb2
1 changed files with 11 additions and 7 deletions
|
@ -54,16 +54,20 @@ class SensorBackend(Backend):
|
||||||
|
|
||||||
if self.thresholds:
|
if self.thresholds:
|
||||||
if isinstance(self.thresholds, dict) and isinstance(new_data, dict):
|
if isinstance(self.thresholds, dict) and isinstance(new_data, dict):
|
||||||
for (measure, threshold) in self.thresholds.items():
|
for (measure, thresholds) in self.thresholds.items():
|
||||||
if measure not in new_data:
|
if measure not in new_data:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if new_data[measure] > threshold and (self.data is None or (
|
if not isinstance(thresholds, list):
|
||||||
measure in self.data and self.data[measure] <= threshold)):
|
thresholds = [thresholds]
|
||||||
data_above_threshold[measure] = new_data[measure]
|
|
||||||
elif new_data[measure] < threshold and (self.data is None or (
|
for threshold in thresholds:
|
||||||
measure in self.data and self.data[measure] >= threshold)):
|
if new_data[measure] > threshold and (self.data is None or (
|
||||||
data_below_threshold[measure] = new_data[measure]
|
measure in self.data and self.data[measure] <= threshold)):
|
||||||
|
data_above_threshold[measure] = new_data[measure]
|
||||||
|
elif new_data[measure] < threshold and (self.data is None or (
|
||||||
|
measure in self.data and self.data[measure] >= threshold)):
|
||||||
|
data_below_threshold[measure] = new_data[measure]
|
||||||
|
|
||||||
if data_below_threshold:
|
if data_below_threshold:
|
||||||
self.bus.post(SensorDataBelowThresholdEvent(data=data_below_threshold))
|
self.bus.post(SensorDataBelowThresholdEvent(data=data_below_threshold))
|
||||||
|
|
Loading…
Reference in a new issue