Skip to content

Commit

Permalink
Update Schedule sensors from cache on top of hour
Browse files Browse the repository at this point in the history
  • Loading branch information
PimDoos committed Feb 23, 2025
1 parent abd6564 commit 7eeef42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/sessy/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def setup_coordinators(hass, config_entry: SessyConfigEntry, device: Sessy

if isinstance(device, SessyBattery):
coordinators.extend([
SessyCoordinator(hass, config_entry, device.get_dynamic_schedule), # TODO align to hour, only poll once every hour
SessyCoordinator(hass, config_entry, device.get_dynamic_schedule, SCAN_INTERVAL_SCHEDULE),
SessyCoordinator(hass, config_entry, device.get_power_status, scan_interval_power),
SessyCoordinator(hass, config_entry, device.get_power_strategy),
SessyCoordinator(hass, config_entry, device.get_system_settings),
Expand Down
7 changes: 7 additions & 0 deletions custom_components/sessy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, SensorStateClass
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.event import async_track_time_change

from sessypy.const import SessySystemState, SessyP1State
from sessypy.devices import SessyBattery, SessyDevice, SessyP1Meter, SessyCTMeter
Expand Down Expand Up @@ -384,6 +385,12 @@ def __init__(self, hass: HomeAssistant, config_entry: SessyConfigEntry, name: st
precision=precision, enabled_default=enabled_default)

self.schedule_key = schedule_key

async def update_schedule(event_time_utc: datetime = None):
self.update_from_cache()

# Update on top of hour
self.tracker = async_track_time_change(hass, update_schedule, None, 0, 0)

def update_from_cache(self):
now = datetime.now()
Expand Down

0 comments on commit 7eeef42

Please sign in to comment.