Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions custom_components/hilo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
)
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.util import dt as dt_util, slugify
from packaging.version import Version
from pyhilo import API
Expand Down Expand Up @@ -73,6 +72,7 @@
LOG,
MIN_SCAN_INTERVAL,
)
from .coordinator import HiloCoordinator
from .oauth2 import AuthCodeWithPKCEImplementation

DISPATCHER_TOPIC_SIGNALR_EVENT = "pyhilo_signalr_event"
Expand Down Expand Up @@ -434,7 +434,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry, api: API) -> None:
)
self.cost_sensors: dict = {}
# This will get filled in by async_init:
self.coordinator: DataUpdateCoordinator | None = None
self.coordinator: HiloCoordinator | None = None
self.unknown_tracker_device: HiloDevice | None = None
self._events: dict = {}
if self.track_unknown_sources:
Expand Down Expand Up @@ -916,12 +916,8 @@ async def signalr_disconnect_listener(_: Event) -> None:
EVENT_HOMEASSISTANT_STOP, signalr_disconnect_listener
)
)
self.coordinator = DataUpdateCoordinator(
self._hass,
LOG,
name="hilo",
update_interval=timedelta(seconds=scan_interval),
update_method=self.async_update,
self.coordinator = HiloCoordinator(
self._hass, self.entry, self, timedelta(seconds=scan_interval)
)

async def start_signalr_loop(self, hub, id) -> None:
Expand Down
44 changes: 44 additions & 0 deletions custom_components/hilo/coordinator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""DataUpdateCoordinator for the Hilo integration."""

from __future__ import annotations

from datetime import timedelta
from typing import TYPE_CHECKING

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import LOG

if TYPE_CHECKING:
from . import Hilo


class HiloCoordinator(DataUpdateCoordinator[None]):
"""Periodically recompute tariff and unknown power state.

Device state is pushed into python-hilo by SignalR and GraphQL, so this
coordinator does not fetch it; entities only use it as a refresh tick.
"""

def __init__(
self,
hass: HomeAssistant,
config_entry: ConfigEntry,
hilo: Hilo,
update_interval: timedelta,
) -> None:
"""Initialize the coordinator."""
super().__init__(
hass,
LOG,
config_entry=config_entry,
name="hilo",
update_interval=update_interval,
)
self._hilo = hilo

async def _async_update_data(self) -> None:
"""Run the periodic tariff and unknown power updates."""
await self._hilo.async_update()
4 changes: 2 additions & 2 deletions custom_components/hilo/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ rules:
comment: Devices and challenges are push (SignalR); only notifications, weather and rewards poll (30 min-2 h).
brands: done
common-modules:
status: todo
comment: entity.py exists; coordinator.py does not.
status: done
comment: coordinator.py only drives the tariff tick; device data does not flow through it yet.
config-flow-test-coverage: todo
config-flow: done
dependency-transparency: done
Expand Down
Loading