1 """The ReCollect Waste integration."""
3 from __future__
import annotations
5 from datetime
import date, timedelta
8 from aiorecollect.client
import Client, PickupEvent
9 from aiorecollect.errors
import RecollectError
17 from .const
import CONF_PLACE_ID, CONF_SERVICE_ID, DOMAIN, LOGGER
19 DEFAULT_NAME =
"recollect_waste"
22 PLATFORMS = [Platform.CALENDAR, Platform.SENSOR]
26 """Set up RainMachine as config entry."""
27 session = aiohttp_client.async_get_clientsession(hass)
29 entry.data[CONF_PLACE_ID], entry.data[CONF_SERVICE_ID], session=session
32 async
def async_get_pickup_events() -> list[PickupEvent]:
33 """Get the next pickup."""
43 return await client.async_get_pickup_events(
47 except RecollectError
as err:
49 f
"Error while requesting data from ReCollect: {err}"
57 f
"Place {entry.data[CONF_PLACE_ID]}, Service {entry.data[CONF_SERVICE_ID]}"
59 update_interval=DEFAULT_UPDATE_INTERVAL,
60 update_method=async_get_pickup_events,
63 await coordinator.async_config_entry_first_refresh()
64 hass.data.setdefault(DOMAIN, {})
65 hass.data[DOMAIN][entry.entry_id] = coordinator
67 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
69 entry.async_on_unload(entry.add_update_listener(async_reload_entry))
75 """Handle an options update."""
76 await hass.config_entries.async_reload(entry.entry_id)
80 """Unload an RainMachine config entry."""
81 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
83 hass.data[DOMAIN].pop(entry.entry_id)
89 """Migrate an old config entry."""
90 version = entry.version
92 LOGGER.debug(
"Migrating from version %s", version)
98 hass.config_entries.async_update_entry(entry, version=version)
101 def migrate_unique_id(entity_entry: er.RegistryEntry) -> dict[str, Any]:
102 """Migrate the unique ID to a new format."""
105 f
"{entry.data[CONF_PLACE_ID]}_"
106 f
"{entry.data[CONF_SERVICE_ID]}_"
111 await er.async_migrate_entries(hass, entry.entry_id, migrate_unique_id)
113 LOGGER.debug(
"Migration to version %s successful", version)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
None async_reload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_migrate_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)