1 """The Landis+Gyr Heat Meter integration."""
3 from __future__
import annotations
15 from .const
import DOMAIN
16 from .coordinator
import UltraheatCoordinator
18 _LOGGER = logging.getLogger(__name__)
20 PLATFORMS: list[Platform] = [Platform.SENSOR]
24 """Set up heat meter from a config entry."""
26 _LOGGER.debug(
"Initializing %s integration on %s", DOMAIN, entry.data[CONF_DEVICE])
27 reader = ultraheat_api.UltraheatReader(entry.data[CONF_DEVICE])
28 api = ultraheat_api.HeatMeterService(reader)
31 await coordinator.async_config_entry_first_refresh()
33 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
35 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
41 """Unload a config entry."""
42 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
43 hass.data[DOMAIN].pop(entry.entry_id)
49 """Migrate old entry."""
50 _LOGGER.debug(
"Migrating from version %s", config_entry.version)
53 if config_entry.version == 1:
54 hass.config_entries.async_update_entry(config_entry, version=2)
56 device_number = config_entry.data[
"device_number"]
59 def update_entity_unique_id(
60 entity_entry: RegistryEntry,
61 ) -> dict[str, Any] |
None:
62 """Update unique ID of entity entry."""
63 if entity_entry.platform
in entity_entry.unique_id:
65 "new_unique_id": entity_entry.unique_id.replace(
66 f
"{entity_entry.platform}_{entity_entry.config_entry_id}",
73 hass, config_entry.entry_id, update_entity_unique_id
76 _LOGGER.debug(
"Migration to version %s successful", config_entry.version)
None async_migrate_entries(HomeAssistant hass, dict[str, AdapterDetails] adapters, str default_adapter)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_migrate_entry(HomeAssistant hass, ConfigEntry config_entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)