The to-do list exists so Home Assistant's own conversation agent can manage the order through HassListAddItem rather than through anything bespoke. Skip is a switch because skipped/not-skipped is state worth reading back; donate is a button because it cannot be undone. Un-skip raises rather than guessing at an endpoint that has never been observed. Fixes subscription parsing, which matched the heading row and so reported zero on an account that has one.
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
"""The Fresh Harvest integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
|
|
|
from .api import FreshHarvestClient
|
|
from .coordinator import FreshHarvestCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [
|
|
Platform.BINARY_SENSOR,
|
|
Platform.BUTTON,
|
|
Platform.SENSOR,
|
|
Platform.SWITCH,
|
|
Platform.TODO,
|
|
]
|
|
|
|
type FreshHarvestConfigEntry = ConfigEntry[FreshHarvestCoordinator]
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant, entry: FreshHarvestConfigEntry
|
|
) -> bool:
|
|
"""Set up Fresh Harvest from a config entry."""
|
|
# Dedicated session: the login tokens are bound to its cookie jar.
|
|
session = async_create_clientsession(hass)
|
|
client = FreshHarvestClient(
|
|
session, entry.data[CONF_EMAIL], entry.data[CONF_PASSWORD]
|
|
)
|
|
|
|
coordinator = FreshHarvestCoordinator(hass, entry, client)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
entry.runtime_data = coordinator
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(
|
|
hass: HomeAssistant, entry: FreshHarvestConfigEntry
|
|
) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|