1
0
mirror of https://github.com/home-assistant/core.git synced 2026-06-30 19:26:31 +01:00
Files
core/homeassistant/components/openhome/__init__.py
T
epenet 69fd6532cc Migrate openhome to use runtime_data (#167183)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 11:51:31 +02:00

61 lines
1.7 KiB
Python

"""The openhome component."""
import logging
import aiohttp
from async_upnp_client.client import UpnpError
from openhomedevice.device import Device
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN
from .services import async_setup_services
_LOGGER = logging.getLogger(__name__)
type OpenhomeConfigEntry = ConfigEntry[Device]
CONFIG_SCHEMA = cv.empty_config_schema(DOMAIN)
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.UPDATE]
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the component."""
async_setup_services(hass)
return True
async def async_setup_entry(
hass: HomeAssistant,
config_entry: OpenhomeConfigEntry,
) -> bool:
"""Set up the configuration config entry."""
_LOGGER.debug("Setting up config entry: %s", config_entry.unique_id)
device = await hass.async_add_executor_job(Device, config_entry.data[CONF_HOST])
try:
await device.init()
except (TimeoutError, aiohttp.ClientError, UpnpError) as exc:
raise ConfigEntryNotReady from exc
_LOGGER.debug("Initialised device: %s", device.uuid())
config_entry.runtime_data = device
await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
return True
async def async_unload_entry(
hass: HomeAssistant, config_entry: OpenhomeConfigEntry
) -> bool:
"""Cleanup before removing config entry."""
return await hass.config_entries.async_unload_platforms(config_entry, PLATFORMS)