1
mirror of https://github.com/home-assistant/core synced 2024-10-13 14:52:10 +02:00
ha-core/homeassistant/components/roon/__init__.py
Greg Dowling 23264c8fd4
Improve roon integraton (#66000)
* Update to new library, revise discovery to work with new library, specify port to work with new library.

* Move user gui to fallback.

* Revise tests.

* Handle old config.

* Improve debugging, refresh faster on load.

* Remove duplicate.

* Bump library version.

* Fix docstring per review.

* Review suggestion

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Review suggestion

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Add check for duplicate host.

* Add error message to strings.

* Tidy.

* Review changes.

* Remove default.

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-04-18 16:27:14 +02:00

38 lines
1.2 KiB
Python

"""Roon (www.roonlabs.com) component."""
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from .const import CONF_ROON_NAME, DOMAIN
from .server import RoonServer
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a roonserver from a config entry."""
hass.data.setdefault(DOMAIN, {})
# 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
hass.data[DOMAIN][entry.entry_id] = 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})",
)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
roonserver = hass.data[DOMAIN].pop(entry.entry_id)
return await roonserver.async_reset()