1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-01 21:24:17 +01:00
Files
epenet 6dc391e169 Use runtime_data in obihai integration (#167037)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-01 09:47:03 +02:00

53 lines
1.6 KiB
Python

"""The Obihai integration."""
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import format_mac
from .connectivity import ObihaiConnection
from .const import LOGGER, PLATFORMS
type ObihaiConfigEntry = ConfigEntry[ObihaiConnection]
async def async_setup_entry(hass: HomeAssistant, entry: ObihaiConfigEntry) -> bool:
"""Set up from a config entry."""
requester = ObihaiConnection(
entry.data[CONF_HOST],
username=entry.data[CONF_USERNAME],
password=entry.data[CONF_PASSWORD],
)
await hass.async_add_executor_job(requester.update)
entry.runtime_data = requester
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_migrate_entry(hass: HomeAssistant, entry: ObihaiConfigEntry) -> bool:
"""Migrate old entry."""
version = entry.version
LOGGER.debug("Migrating from version %s", version)
if version != 2:
requester = entry.runtime_data
device_mac = await hass.async_add_executor_job(
requester.pyobihai.get_device_mac
)
hass.config_entries.async_update_entry(
entry, unique_id=format_mac(device_mac), version=2
)
LOGGER.debug("Migration to version %s successful", entry.version)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ObihaiConfigEntry) -> bool:
"""Unload a config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)