mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Explicitly pass in the config_entry in Bluesound coordinator init (#137461)
* explicitly pass in the config_entry in coordinator init * remove unneccessary assert
This commit is contained in:
parent
12095df4fa
commit
db6bd6aad1
@ -1,8 +1,6 @@
|
|||||||
"""The bluesound component."""
|
"""The bluesound component."""
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from pyblu import Player
|
||||||
|
|
||||||
from pyblu import Player, SyncStatus
|
|
||||||
from pyblu.errors import PlayerUnreachableError
|
from pyblu.errors import PlayerUnreachableError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -14,7 +12,11 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import BluesoundCoordinator
|
from .coordinator import (
|
||||||
|
BluesoundConfigEntry,
|
||||||
|
BluesoundCoordinator,
|
||||||
|
BluesoundRuntimeData,
|
||||||
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
|
|
||||||
@ -23,18 +25,6 @@ PLATFORMS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class BluesoundRuntimeData:
|
|
||||||
"""Bluesound data class."""
|
|
||||||
|
|
||||||
player: Player
|
|
||||||
sync_status: SyncStatus
|
|
||||||
coordinator: BluesoundCoordinator
|
|
||||||
|
|
||||||
|
|
||||||
type BluesoundConfigEntry = ConfigEntry[BluesoundRuntimeData]
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Bluesound."""
|
"""Set up the Bluesound."""
|
||||||
return True
|
return True
|
||||||
@ -53,7 +43,7 @@ async def async_setup_entry(
|
|||||||
except PlayerUnreachableError as ex:
|
except PlayerUnreachableError as ex:
|
||||||
raise ConfigEntryNotReady(f"Error connecting to {host}:{port}") from ex
|
raise ConfigEntryNotReady(f"Error connecting to {host}:{port}") from ex
|
||||||
|
|
||||||
coordinator = BluesoundCoordinator(hass, player, sync_status)
|
coordinator = BluesoundCoordinator(hass, config_entry, player, sync_status)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
config_entry.runtime_data = BluesoundRuntimeData(player, sync_status, coordinator)
|
config_entry.runtime_data = BluesoundRuntimeData(player, sync_status, coordinator)
|
||||||
|
@ -12,6 +12,7 @@ import logging
|
|||||||
from pyblu import Input, Player, Preset, Status, SyncStatus
|
from pyblu import Input, Player, Preset, Status, SyncStatus
|
||||||
from pyblu.errors import PlayerUnreachableError
|
from pyblu.errors import PlayerUnreachableError
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
|
|
||||||
@ -21,6 +22,15 @@ NODE_OFFLINE_CHECK_TIMEOUT = timedelta(minutes=3)
|
|||||||
PRESET_AND_INPUTS_INTERVAL = timedelta(minutes=15)
|
PRESET_AND_INPUTS_INTERVAL = timedelta(minutes=15)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class BluesoundRuntimeData:
|
||||||
|
"""Bluesound data class."""
|
||||||
|
|
||||||
|
player: Player
|
||||||
|
sync_status: SyncStatus
|
||||||
|
coordinator: BluesoundCoordinator
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BluesoundData:
|
class BluesoundData:
|
||||||
"""Define a class to hold Bluesound data."""
|
"""Define a class to hold Bluesound data."""
|
||||||
@ -31,6 +41,9 @@ class BluesoundData:
|
|||||||
inputs: list[Input]
|
inputs: list[Input]
|
||||||
|
|
||||||
|
|
||||||
|
type BluesoundConfigEntry = ConfigEntry[BluesoundRuntimeData]
|
||||||
|
|
||||||
|
|
||||||
def cancel_task(task: asyncio.Task) -> Callable[[], Coroutine[None, None, None]]:
|
def cancel_task(task: asyncio.Task) -> Callable[[], Coroutine[None, None, None]]:
|
||||||
"""Cancel a task."""
|
"""Cancel a task."""
|
||||||
|
|
||||||
@ -45,8 +58,14 @@ def cancel_task(task: asyncio.Task) -> Callable[[], Coroutine[None, None, None]]
|
|||||||
class BluesoundCoordinator(DataUpdateCoordinator[BluesoundData]):
|
class BluesoundCoordinator(DataUpdateCoordinator[BluesoundData]):
|
||||||
"""Define an object to hold Bluesound data."""
|
"""Define an object to hold Bluesound data."""
|
||||||
|
|
||||||
|
config_entry: BluesoundConfigEntry
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: HomeAssistant, player: Player, sync_status: SyncStatus
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: BluesoundConfigEntry,
|
||||||
|
player: Player,
|
||||||
|
sync_status: SyncStatus,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
self.player = player
|
self.player = player
|
||||||
@ -55,12 +74,11 @@ class BluesoundCoordinator(DataUpdateCoordinator[BluesoundData]):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
logger=_LOGGER,
|
logger=_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=sync_status.name,
|
name=sync_status.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_setup(self) -> None:
|
async def _async_setup(self) -> None:
|
||||||
assert self.config_entry is not None
|
|
||||||
|
|
||||||
preset = await self.player.presets()
|
preset = await self.player.presets()
|
||||||
inputs = await self.player.inputs()
|
inputs = await self.player.inputs()
|
||||||
status = await self.player.status()
|
status = await self.player.status()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user