2020-05-17 10:15:06 +00:00
|
|
|
"""The Rollease Acmeda Automate integration."""
|
2024-03-08 13:51:32 +00:00
|
|
|
|
2022-01-19 17:00:34 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-03 16:51:30 +00:00
|
|
|
from homeassistant.const import Platform
|
2022-01-19 17:00:34 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2025-01-28 07:48:34 +00:00
|
|
|
from homeassistant.helpers import entity_registry as er
|
2020-05-17 10:15:06 +00:00
|
|
|
|
|
|
|
from .hub import PulseHub
|
|
|
|
|
|
|
|
CONF_HUBS = "hubs"
|
|
|
|
|
2021-12-03 16:51:30 +00:00
|
|
|
PLATFORMS = [Platform.COVER, Platform.SENSOR]
|
2020-05-17 10:15:06 +00:00
|
|
|
|
2024-05-17 13:42:58 +00:00
|
|
|
type AcmedaConfigEntry = ConfigEntry[PulseHub]
|
2020-05-17 10:15:06 +00:00
|
|
|
|
2024-05-02 11:40:49 +00:00
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, config_entry: AcmedaConfigEntry
|
|
|
|
) -> bool:
|
2020-05-17 10:15:06 +00:00
|
|
|
"""Set up Rollease Acmeda Automate hub from a config entry."""
|
2024-09-08 08:42:54 +00:00
|
|
|
|
|
|
|
await _migrate_unique_ids(hass, config_entry)
|
|
|
|
|
2020-05-17 10:15:06 +00:00
|
|
|
hub = PulseHub(hass, config_entry)
|
|
|
|
|
|
|
|
if not await hub.async_setup():
|
|
|
|
return False
|
|
|
|
|
2024-05-02 11:40:49 +00:00
|
|
|
config_entry.runtime_data = hub
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
|
2020-05-17 10:15:06 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2024-09-08 08:42:54 +00:00
|
|
|
async def _migrate_unique_ids(hass: HomeAssistant, entry: AcmedaConfigEntry) -> None:
|
|
|
|
"""Migrate pre-config flow unique ids."""
|
|
|
|
entity_registry = er.async_get(hass)
|
|
|
|
registry_entries = er.async_entries_for_config_entry(
|
|
|
|
entity_registry, entry.entry_id
|
|
|
|
)
|
|
|
|
for reg_entry in registry_entries:
|
|
|
|
if isinstance(reg_entry.unique_id, int): # type: ignore[unreachable]
|
|
|
|
entity_registry.async_update_entity( # type: ignore[unreachable]
|
|
|
|
reg_entry.entity_id, new_unique_id=str(reg_entry.unique_id)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-05-02 11:40:49 +00:00
|
|
|
async def async_unload_entry(
|
|
|
|
hass: HomeAssistant, config_entry: AcmedaConfigEntry
|
|
|
|
) -> bool:
|
2020-05-17 10:15:06 +00:00
|
|
|
"""Unload a config entry."""
|
2024-05-02 11:40:49 +00:00
|
|
|
hub = config_entry.runtime_data
|
2020-05-17 10:15:06 +00:00
|
|
|
|
2021-04-26 17:46:55 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
|
|
|
config_entry, PLATFORMS
|
2020-05-17 10:15:06 +00:00
|
|
|
)
|
2021-04-26 17:46:55 +00:00
|
|
|
|
2020-05-17 10:15:06 +00:00
|
|
|
if not await hub.async_reset():
|
|
|
|
return False
|
|
|
|
|
|
|
|
return unload_ok
|