Skip to content

Commit

Permalink
Skipping events received within 30 seconds of each other
Browse files Browse the repository at this point in the history
  • Loading branch information
valleedelisle committed Dec 16, 2023
1 parent 6a05f4c commit d658a15
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions custom_components/hilo/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down

0 comments on commit d658a15

Please sign in to comment.