From d658a1592745c32695832a153487f23767c1b6bc Mon Sep 17 00:00:00 2001 From: David Vallee Delisle Date: Sat, 16 Dec 2023 10:18:06 -0500 Subject: [PATCH] Skipping events received within 30 seconds of each other --- custom_components/hilo/sensor.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/custom_components/hilo/sensor.py b/custom_components/hilo/sensor.py index 5f22c58..d3b3ab9 100755 --- a/custom_components/hilo/sensor.py +++ b/custom_components/hilo/sensor.py @@ -774,13 +774,17 @@ def _handle_state_change(self, event): return if state.entity_id != f"sensor.{self._attr_unique_id}": return + now = dt_util.utcnow() try: - if state.attributes.get("hilo_update"): + if ( + state.attributes.get("hilo_update") + and self._last_update + timedelta(seconds=30) < now + ): LOG.debug( f"Setting new state {state.state} {state=} {state.attributes=}" ) self._cost = state.state - self._last_update = dt_util.utcnow() + self._last_update = now except ValueError: LOG.error(f"Invalidate state received for {self._attr_unique_id}: {state}")