Files
ha-freshharvest/custom_components/freshharvest/__init__.py
T
flan e7427082e3
Validate / hassfest (push) Failing after 6s
Validate / pytest (push) Failing after 10s
Validate / HACS (push) Failing after 17s
Wire produce-box switching as a select entity
The boxes are not in the Algolia catalogue and their category pages look empty
because the grid calls every option 'Georgia Box' — each option's real name is
only in its own select-basket popup, so listing reads them there.

POST /s/submit/select-basket carries a scope the add-on endpoints do not:
popup-toggle is 'do' for the next delivery or 'so' for the standing order. The
select uses 'do', because a mistaken permanent change is the worse one to undo.

Also makes the popup regexes whitespace-tolerant. The site writes both
openPopup("x","y") and openPopup("x", "y"), and the strict form silently
matched nothing on the basket pages.
2026-08-03 20:31:13 +00:00

48 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.SELECT,
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)