mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 23:41:48 -05:00
Use runtime_data in ridwell integration (#167658)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
8d3d4a1b5c
commit
2e6137325c
@@ -9,17 +9,17 @@ from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .const import DOMAIN, LOGGER, SENSOR_TYPE_NEXT_PICKUP
|
||||
from .coordinator import RidwellDataUpdateCoordinator
|
||||
from .const import LOGGER, SENSOR_TYPE_NEXT_PICKUP
|
||||
from .coordinator import RidwellConfigEntry, RidwellDataUpdateCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.CALENDAR, Platform.SENSOR, Platform.SWITCH]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: RidwellConfigEntry) -> bool:
|
||||
"""Set up Ridwell from a config entry."""
|
||||
coordinator = RidwellDataUpdateCoordinator(hass, entry)
|
||||
await coordinator.async_initialize()
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||
entry.runtime_data = coordinator
|
||||
entry.async_on_unload(entry.add_update_listener(options_update_listener))
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
@@ -27,17 +27,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
async def options_update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
async def options_update_listener(
|
||||
hass: HomeAssistant, entry: RidwellConfigEntry
|
||||
) -> None:
|
||||
"""Handle options update."""
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: RidwellConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
|
||||
async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
@@ -7,7 +7,6 @@ import datetime
|
||||
from aioridwell.model import PickupCategory, RidwellAccount, RidwellPickupEvent
|
||||
|
||||
from homeassistant.components.calendar import CalendarEntity, CalendarEvent
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
@@ -16,15 +15,14 @@ from .const import (
|
||||
CALENDAR_TITLE_ROTATING,
|
||||
CALENDAR_TITLE_STATUS,
|
||||
CONF_CALENDAR_TITLE,
|
||||
DOMAIN,
|
||||
)
|
||||
from .coordinator import RidwellDataUpdateCoordinator
|
||||
from .coordinator import RidwellConfigEntry, RidwellDataUpdateCoordinator
|
||||
from .entity import RidwellEntity
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_calendar_event_from_pickup_event(
|
||||
pickup_event: RidwellPickupEvent, config_entry: ConfigEntry
|
||||
pickup_event: RidwellPickupEvent, config_entry: RidwellConfigEntry
|
||||
) -> CalendarEvent:
|
||||
"""Get a HASS CalendarEvent from an aioridwell PickupEvent."""
|
||||
pickup_items = []
|
||||
@@ -66,11 +64,11 @@ def async_get_calendar_event_from_pickup_event(
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: RidwellConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Ridwell calendars based on a config entry."""
|
||||
coordinator: RidwellDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
RidwellCalendar(coordinator, account)
|
||||
|
||||
@@ -9,7 +9,7 @@ from aioridwell import async_get_client
|
||||
from aioridwell.errors import InvalidCredentialsError, RidwellError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import aiohttp_client, config_validation as cv, selector
|
||||
@@ -19,6 +19,7 @@ from homeassistant.helpers.schema_config_entry_flow import (
|
||||
)
|
||||
|
||||
from .const import CALENDAR_TITLE_OPTIONS, CONF_CALENDAR_TITLE, DOMAIN, LOGGER
|
||||
from .coordinator import RidwellConfigEntry
|
||||
|
||||
STEP_REAUTH_CONFIRM_DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
@@ -107,7 +108,7 @@ class RidwellConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: RidwellConfigEntry,
|
||||
) -> SchemaOptionsFlowHandler:
|
||||
"""Get options flow for this handler."""
|
||||
try:
|
||||
|
||||
@@ -19,6 +19,8 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
|
||||
|
||||
from .const import LOGGER
|
||||
|
||||
type RidwellConfigEntry = ConfigEntry[RidwellDataUpdateCoordinator]
|
||||
|
||||
UPDATE_INTERVAL = timedelta(hours=1)
|
||||
|
||||
|
||||
@@ -27,9 +29,9 @@ class RidwellDataUpdateCoordinator(
|
||||
):
|
||||
"""Class to manage fetching data from single endpoint."""
|
||||
|
||||
config_entry: ConfigEntry
|
||||
config_entry: RidwellConfigEntry
|
||||
|
||||
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||
def __init__(self, hass: HomeAssistant, config_entry: RidwellConfigEntry) -> None:
|
||||
"""Initialize."""
|
||||
# These will be filled in by async_initialize; we give them these defaults to
|
||||
# avoid arduous typing checks down the line:
|
||||
|
||||
@@ -6,12 +6,10 @@ import dataclasses
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_UNIQUE_ID, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import RidwellDataUpdateCoordinator
|
||||
from .coordinator import RidwellConfigEntry
|
||||
|
||||
CONF_TITLE = "title"
|
||||
|
||||
@@ -25,17 +23,15 @@ TO_REDACT = {
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: ConfigEntry
|
||||
hass: HomeAssistant, entry: RidwellConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator: RidwellDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
return async_redact_data(
|
||||
{
|
||||
"entry": entry.as_dict(),
|
||||
"data": [
|
||||
dataclasses.asdict(event)
|
||||
for events in coordinator.data.values()
|
||||
for events in entry.runtime_data.data.values()
|
||||
for event in events
|
||||
],
|
||||
},
|
||||
|
||||
@@ -13,12 +13,11 @@ from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import DOMAIN, SENSOR_TYPE_NEXT_PICKUP
|
||||
from .coordinator import RidwellDataUpdateCoordinator
|
||||
from .const import SENSOR_TYPE_NEXT_PICKUP
|
||||
from .coordinator import RidwellConfigEntry, RidwellDataUpdateCoordinator
|
||||
from .entity import RidwellEntity
|
||||
|
||||
ATTR_CATEGORY = "category"
|
||||
@@ -35,11 +34,11 @@ SENSOR_DESCRIPTION = SensorEntityDescription(
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: RidwellConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Ridwell sensors based on a config entry."""
|
||||
coordinator: RidwellDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
RidwellSensor(coordinator, account, SENSOR_DESCRIPTION)
|
||||
|
||||
@@ -8,13 +8,11 @@ from aioridwell.errors import RidwellError
|
||||
from aioridwell.model import EventState, RidwellAccount
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity, SwitchEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import RidwellDataUpdateCoordinator
|
||||
from .coordinator import RidwellConfigEntry, RidwellDataUpdateCoordinator
|
||||
from .entity import RidwellEntity
|
||||
|
||||
SWITCH_DESCRIPTION = SwitchEntityDescription(
|
||||
@@ -25,11 +23,11 @@ SWITCH_DESCRIPTION = SwitchEntityDescription(
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: RidwellConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up Ridwell sensors based on a config entry."""
|
||||
coordinator: RidwellDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
RidwellSwitch(coordinator, account, SWITCH_DESCRIPTION)
|
||||
|
||||
Reference in New Issue
Block a user