From 9684e1ae7f5bcf574a40ba0291efc79a86364f84 Mon Sep 17 00:00:00 2001 From: Dave Brand Date: Wed, 27 Nov 2024 10:47:32 -0500 Subject: [PATCH] =?UTF-8?q?Filter,=20config=20Based=20on=20deleted=20branc?= =?UTF-8?q?h=20by=20Daniel=20Hjelseth=20H=C3=B8yer=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- homeassistant/components/filter/sensor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/filter/sensor.py b/homeassistant/components/filter/sensor.py index e9ea235db150ea..1f7a91f26392a9 100644 --- a/homeassistant/components/filter/sensor.py +++ b/homeassistant/components/filter/sensor.py @@ -69,6 +69,7 @@ CONF_FILTER_PRECISION = "precision" CONF_FILTER_RADIUS = "radius" CONF_FILTER_TIME_CONSTANT = "time_constant" +CONF_FILTER_UPDATE_BY_TIME = "update_by_time" CONF_FILTER_LOWER_BOUND = "lower_bound" CONF_FILTER_UPPER_BOUND = "upper_bound" CONF_TIME_SMA_TYPE = "type" @@ -86,7 +87,7 @@ NAME_TEMPLATE = "{} filter" ICON = "mdi:chart-line-variant" -SCAN_INTERVAL = timedelta(minutes=10) +SCAN_INTERVAL = timedelta(minutes=3) FILTER_SCHEMA = vol.Schema({vol.Optional(CONF_FILTER_PRECISION): vol.Coerce(int)}) @@ -131,6 +132,7 @@ vol.Required(CONF_FILTER_WINDOW_SIZE): vol.All( cv.time_period, cv.positive_timedelta ), + vol.Optional(CONF_FILTER_UPDATE_BY_TIME, default=False): cv.boolean, } ) @@ -227,7 +229,7 @@ def __init__( self._attr_should_poll = False for filt in filters: - if isinstance(filt, TimeSMAFilter): + if getattr(filt, "update_by_time", False): self._attr_should_poll = True break @@ -661,6 +663,7 @@ def __init__( entity: str, type: str, # pylint: disable=redefined-builtin precision: int = DEFAULT_PRECISION, + update_by_time: bool = False, ) -> None: """Initialize Filter. @@ -670,6 +673,7 @@ def __init__( FILTER_NAME_TIME_SMA, window_size, precision=precision, entity=entity ) self._time_window = window_size + self.update_by_time = update_by_time self.last_leak: FilterState | None = None self.queue = deque[FilterState]()