-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinator.py
More file actions
54 lines (40 loc) · 1.72 KB
/
coordinator.py
File metadata and controls
54 lines (40 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Coordinator for DVSPortal integration."""
from dataclasses import dataclass
from datetime import timedelta
import logging
from dvsportal import DVSPortal, HistoricReservation, Reservation
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
@dataclass
class DVSPortalData:
"""Data class for DVSPortal coordinator data."""
default_code: str | None
default_type_id: int | None
balance: float | None
active_reservations: dict[str, Reservation]
historic_reservations: dict[str, HistoricReservation]
known_license_plates: dict[str, str] # historic, saved or reserved license plates
class DVSPortalCoordinator(DataUpdateCoordinator[DVSPortalData]):
"""Class to manage fetching data from the DVSPortal API."""
def __init__(self, hass: HomeAssistant, dvs_portal: DVSPortal) -> None:
"""Initialize the coordinator."""
super().__init__(
hass,
_LOGGER,
name=f"{DOMAIN}_coordinator",
update_interval=timedelta(minutes=5),
)
self.dvs_portal = dvs_portal
async def _async_update_data(self) -> DVSPortalData:
"""Fetch data from the DVSPortal API."""
await self.dvs_portal.update()
return DVSPortalData(
default_code=self.dvs_portal.default_code,
default_type_id=self.dvs_portal.default_type_id,
balance=self.dvs_portal.balance,
active_reservations=self.dvs_portal.active_reservations,
historic_reservations=self.dvs_portal.historic_reservations,
known_license_plates=self.dvs_portal.known_license_plates,
)