"""Roon (www.roonlabs.com) component.""" from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import config_validation as cv, device_registry as dr from homeassistant.helpers.typing import ConfigType from .const import CONF_ROON_NAME, DOMAIN from .server import RoonServer from .services import async_setup_services type RoonConfigEntry = ConfigEntry[RoonServer] CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN) PLATFORMS = [Platform.EVENT, Platform.MEDIA_PLAYER] 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, entry: RoonConfigEntry) -> bool: """Set up a roonserver from a config entry.""" # fallback to using host for compatibility with older configs name = entry.data.get(CONF_ROON_NAME, entry.data[CONF_HOST]) roonserver = RoonServer(hass, entry) if not await roonserver.async_setup(): return False entry.runtime_data = roonserver device_registry = dr.async_get(hass) device_registry.async_get_or_create( config_entry_id=entry.entry_id, identifiers={(DOMAIN, entry.entry_id)}, manufacturer="Roonlabs", name=f"Roon Core ({name})", ) # initialize media_player platform await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: RoonConfigEntry) -> bool: """Unload a config entry.""" if not await hass.config_entries.async_unload_platforms(entry, PLATFORMS): return False return await entry.runtime_data.async_reset()