1
mirror of https://github.com/home-assistant/core synced 2024-10-07 10:13:38 +02:00

Fix Roon media player being set up before hass.data set up (#75904)

This commit is contained in:
Paulus Schoutsen 2022-07-29 00:53:08 -07:00 committed by GitHub
parent 4b2beda473
commit aec885a467
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 9 deletions

View File

@ -1,12 +1,14 @@
"""Roon (www.roonlabs.com) component."""
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST
from homeassistant.const import CONF_HOST, Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from .const import CONF_ROON_NAME, DOMAIN
from .server import RoonServer
PLATFORMS = [Platform.MEDIA_PLAYER]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a roonserver from a config entry."""
@ -28,10 +30,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
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: ConfigEntry) -> bool:
"""Unload a config entry."""
if not await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
return False
roonserver = hass.data[DOMAIN].pop(entry.entry_id)
return await roonserver.async_reset()

View File

@ -4,7 +4,7 @@ import logging
from roonapi import RoonApi, RoonDiscovery
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT, Platform
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PORT
from homeassistant.helpers.dispatcher import async_dispatcher_send
from homeassistant.util.dt import utcnow
@ -13,7 +13,6 @@ from .const import CONF_ROON_ID, ROON_APPINFO
_LOGGER = logging.getLogger(__name__)
INITIAL_SYNC_INTERVAL = 5
FULL_SYNC_INTERVAL = 30
PLATFORMS = [Platform.MEDIA_PLAYER]
class RoonServer:
@ -53,7 +52,6 @@ class RoonServer:
(host, port) = get_roon_host()
return RoonApi(ROON_APPINFO, token, host, port, blocking_init=True)
hass = self.hass
core_id = self.config_entry.data.get(CONF_ROON_ID)
self.roonapi = await self.hass.async_add_executor_job(get_roon_api)
@ -67,11 +65,6 @@ class RoonServer:
core_id if core_id is not None else self.config_entry.data[CONF_HOST]
)
# initialize media_player platform
await hass.config_entries.async_forward_entry_setups(
self.config_entry, PLATFORMS
)
# Initialize Roon background polling
asyncio.create_task(self.async_do_loop())