Implement dashboard parsing and delivery sensors
Reads delivery day, next arrival date, both upcoming carts, box contents, add-ons and order totals from a single /p/dashboard/details fetch. Adds five sensors and parser tests over a synthetic fixture mirroring the live markup. Records two portal quirks: every /p/ path returns 200 so signed-in state is detected by a Sign Out control, and cart-contents-skipped marks the locked cart rather than a skipped order.
This commit is contained in:
@@ -9,14 +9,19 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
||||
from .api import Delivery, FreshHarvestAuthError, FreshHarvestClient, FreshHarvestError
|
||||
from .api import (
|
||||
AccountSnapshot,
|
||||
FreshHarvestAuthError,
|
||||
FreshHarvestClient,
|
||||
FreshHarvestError,
|
||||
)
|
||||
from .const import DOMAIN, UPDATE_INTERVAL
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FreshHarvestCoordinator(DataUpdateCoordinator[Delivery]):
|
||||
"""Fetch the account's next delivery."""
|
||||
class FreshHarvestCoordinator(DataUpdateCoordinator[AccountSnapshot]):
|
||||
"""Fetch the account dashboard on a slow interval."""
|
||||
|
||||
def __init__(
|
||||
self, hass: HomeAssistant, entry: ConfigEntry, client: FreshHarvestClient
|
||||
@@ -30,9 +35,9 @@ class FreshHarvestCoordinator(DataUpdateCoordinator[Delivery]):
|
||||
)
|
||||
self.client = client
|
||||
|
||||
async def _async_update_data(self) -> Delivery:
|
||||
async def _async_update_data(self) -> AccountSnapshot:
|
||||
try:
|
||||
return await self.client.async_get_next_delivery()
|
||||
return await self.client.async_get_snapshot()
|
||||
except FreshHarvestAuthError as err:
|
||||
raise ConfigEntryAuthFailed(str(err)) from err
|
||||
except FreshHarvestError as err:
|
||||
|
||||
Reference in New Issue
Block a user