2020-08-12 13:09:47 +00:00
|
|
|
"""Roon (www.roonlabs.com) component."""
|
2022-01-02 15:36:24 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2020-08-12 13:09:47 +00:00
|
|
|
from homeassistant.const import CONF_HOST
|
2022-01-02 15:36:24 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-08-12 13:09:47 +00:00
|
|
|
from homeassistant.helpers import device_registry as dr
|
|
|
|
|
2022-04-18 14:27:14 +00:00
|
|
|
from .const import CONF_ROON_NAME, DOMAIN
|
2020-08-12 13:09:47 +00:00
|
|
|
from .server import RoonServer
|
|
|
|
|
|
|
|
|
2022-01-02 15:36:24 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-08-12 13:09:47 +00:00
|
|
|
"""Set up a roonserver from a config entry."""
|
2021-04-16 15:46:49 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})
|
2022-04-18 14:27:14 +00:00
|
|
|
|
|
|
|
# fallback to using host for compatibility with older configs
|
|
|
|
name = entry.data.get(CONF_ROON_NAME, entry.data[CONF_HOST])
|
|
|
|
|
2020-08-12 13:09:47 +00:00
|
|
|
roonserver = RoonServer(hass, entry)
|
|
|
|
|
|
|
|
if not await roonserver.async_setup():
|
|
|
|
return False
|
|
|
|
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = roonserver
|
2021-10-27 22:58:14 +00:00
|
|
|
device_registry = dr.async_get(hass)
|
2020-08-12 13:09:47 +00:00
|
|
|
device_registry.async_get_or_create(
|
|
|
|
config_entry_id=entry.entry_id,
|
|
|
|
identifiers={(DOMAIN, entry.entry_id)},
|
|
|
|
manufacturer="Roonlabs",
|
2022-04-18 14:27:14 +00:00
|
|
|
name=f"Roon Core ({name})",
|
2020-08-12 13:09:47 +00:00
|
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-01-02 15:36:24 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-08-12 13:09:47 +00:00
|
|
|
"""Unload a config entry."""
|
|
|
|
roonserver = hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return await roonserver.async_reset()
|