More robust sensor tolerance measurement in case of non-numeric sensor data

This commit is contained in:
Fabio Manganiello 2019-08-14 22:45:50 +02:00
parent e7448d90d6
commit 4a34fcd7fd

View file

@ -118,15 +118,25 @@ class SensorBackend(Backend):
if v is None: if v is None:
continue continue
tolerance = None
isNaN = False
try:
v = float(v)
except (TypeError, ValueError):
isNaN = True
if not isNaN:
if isinstance(self.tolerance, dict): if isinstance(self.tolerance, dict):
tolerance = float(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)
except (TypeError, ValueError): except (TypeError, ValueError):
continue pass
if abs(v - self.data.get(k)) >= tolerance: if tolerance is None or isNaN or \
abs(v - self.data.get(k)) >= tolerance:
ret[k] = v ret[k] = v
return ret return ret