add sensor filters

This commit is contained in:
Викторов Андрей Германович
2021-09-21 14:51:33 +03:00
parent 2c58f8e67e
commit 919f1ceb12
4 changed files with 26 additions and 2 deletions

View File

@@ -21,7 +21,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.template import Template
from .entities import MegaPushEntity
from .const import CONF_KEY, TEMP, HUM, W1, W1BUS, CONF_CONV_TEMPLATE, CONF_HEX_TO_FLOAT, DOMAIN, CONF_CUSTOM, \
CONF_SKIP, CONF_FILTER_VALUES, CONF_FILTER_SCALE
CONF_SKIP, CONF_FILTER_VALUES, CONF_FILTER_SCALE, CONF_FILTER_LOW, CONF_FILTER_HIGH
from .hub import MegaD
import re
@@ -116,6 +116,8 @@ class FilterBadValues(MegaPushEntity):
def filter_value(self, value):
if value in self.filter_values \
or (self.filter_low is not None and value < self.filter_low) \
or (self.filter_high is not None and value > self.filter_high) \
or (
self._prev_value is not None
and self.filter_scale is not None
@@ -135,6 +137,14 @@ class FilterBadValues(MegaPushEntity):
def filter_scale(self):
return self.customize.get(CONF_FILTER_SCALE, self.mega.customize.get(CONF_FILTER_SCALE, None))
@property
def filter_low(self):
return self.customize.get(CONF_FILTER_LOW, self.mega.customize.get(CONF_FILTER_LOW, None))
@property
def filter_high(self):
return self.customize.get(CONF_FILTER_HIGH, self.mega.customize.get(CONF_FILTER_HIGH, None))
class MegaI2C(FilterBadValues):