Skip to content

Commit

Permalink
Throttle group power sensor updates to once each second instead of 30…
Browse files Browse the repository at this point in the history
… seconds (#1725)
  • Loading branch information
bramstroker committed Jun 20, 2023
1 parent d0ead96 commit bddd42a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/powercalc/sensors/group.py
Expand Up @@ -446,6 +446,7 @@ class GroupedSensor(BaseEntity, RestoreSensor, SensorEntity):
"""Base class for grouped sensors."""

_attr_should_poll = False
_throttle_interval = 30

def __init__(
self,
Expand Down Expand Up @@ -533,7 +534,7 @@ def _async_hide_members(self, hide: bool) -> None:
registry.async_update_entity(entity_id, hidden_by=hidden_by)

@callback
@Throttle(timedelta(seconds=30))
@Throttle(timedelta(seconds=_throttle_interval))
def on_state_change(self, event: Event) -> None:
"""Triggered when one of the group entities changes state."""
if self.hass.state != CoreState.running: # pragma: no cover
Expand Down Expand Up @@ -591,6 +592,7 @@ class GroupedPowerSensor(GroupedSensor, PowerSensor):
_attr_device_class = SensorDeviceClass.POWER
_attr_state_class = SensorStateClass.MEASUREMENT
_attr_native_unit_of_measurement = UnitOfPower.WATT
_throttle_interval = 1

def calculate_new_state(
self,
Expand Down

0 comments on commit bddd42a

Please sign in to comment.