1 """The zamg component."""
3 from __future__
import annotations
10 from .const
import CONF_STATION_ID, DOMAIN, LOGGER
11 from .coordinator
import ZamgDataUpdateCoordinator
13 PLATFORMS = (Platform.SENSOR, Platform.WEATHER)
17 """Set up Zamg from config entry."""
21 station_id = entry.data[CONF_STATION_ID]
22 coordinator.zamg.set_default_station(station_id)
23 await coordinator.async_config_entry_first_refresh()
25 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
28 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
34 """Unload ZAMG config entry."""
35 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
36 hass.data[DOMAIN].pop(entry.entry_id)
41 hass: HomeAssistant, config_entry: ConfigEntry
43 """Migrate old entry."""
44 entity_registry = er.async_get(hass)
48 """Convert the unique_id from 'name_stationid' to 'station_id'.
50 Example: 'WIEN/HOHE WARTE_11035' --> '11035'.
53 entry.domain == Platform.WEATHER
54 and entry.unique_id != config_entry.data[CONF_STATION_ID]
56 new_unique_id = config_entry.data[CONF_STATION_ID]
58 "Migrating entity '%s' unique_id from '%s' to '%s'",
63 if existing_entity_id := entity_registry.async_get_entity_id(
64 entry.domain, entry.platform, new_unique_id
67 "Cannot migrate to unique_id '%s', already exists for '%s'",
73 "new_unique_id": new_unique_id,
77 await er.async_migrate_entries(hass, config_entry.entry_id, update_unique_id)
dict[str, str]|None update_unique_id(er.RegistryEntry entity_entry, str unique_id)
bool _async_migrate_entries(HomeAssistant hass, ConfigEntry config_entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)