Skip to content

Commit

Permalink
Also throttle updates to group power sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Nov 18, 2023
1 parent 2bd2135 commit 19054ba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/powercalc/sensors/group.py
Expand Up @@ -497,11 +497,12 @@ async def async_added_to_hass(self) -> None:
"%s: Could not restore last state: %s", self.entity_id, err,
)

# throttle group energy updates to only once each 30 seconds
state_listener = Throttle(timedelta(seconds=30))(state_listener)

self._prev_state_store = await PreviousStateStore.async_get_instance(self.hass)

# throttle group updates to only once each X seconds, to prevent overloading the state machine
throttle_secs = 30 if isinstance(self, GroupedEnergySensor) else 5
state_listener = Throttle(timedelta(seconds=throttle_secs))(state_listener)

self.async_on_remove(
async_track_state_change_event(
self.hass,
Expand Down

0 comments on commit 19054ba

Please sign in to comment.