mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Explicitly pass in the config_entry in snapcast coordinator (#137942)
* explicitly pass in the config_entry in coordinator * break up error message
This commit is contained in:
parent
2418ef8e8e
commit
dacb29e7fc
@ -11,15 +11,14 @@ from .coordinator import SnapcastUpdateCoordinator
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Snapcast from a config entry."""
|
"""Set up Snapcast from a config entry."""
|
||||||
host = entry.data[CONF_HOST]
|
coordinator = SnapcastUpdateCoordinator(hass, entry)
|
||||||
port = entry.data[CONF_PORT]
|
|
||||||
coordinator = SnapcastUpdateCoordinator(hass, host, port)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
except OSError as ex:
|
except OSError as ex:
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
f"Could not connect to Snapcast server at {host}:{port}"
|
"Could not connect to Snapcast server at "
|
||||||
|
f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}"
|
||||||
) from ex
|
) from ex
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
||||||
|
@ -6,6 +6,8 @@ import logging
|
|||||||
|
|
||||||
from snapcast.control.server import Snapserver
|
from snapcast.control.server import Snapserver
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
|
|
||||||
@ -15,15 +17,20 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
class SnapcastUpdateCoordinator(DataUpdateCoordinator[None]):
|
class SnapcastUpdateCoordinator(DataUpdateCoordinator[None]):
|
||||||
"""Data update coordinator for pushed data from Snapcast server."""
|
"""Data update coordinator for pushed data from Snapcast server."""
|
||||||
|
|
||||||
def __init__(self, hass: HomeAssistant, host: str, port: int) -> None:
|
config_entry: ConfigEntry
|
||||||
|
|
||||||
|
def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:
|
||||||
"""Initialize coordinator."""
|
"""Initialize coordinator."""
|
||||||
|
host = config_entry.data[CONF_HOST]
|
||||||
|
port = config_entry.data[CONF_PORT]
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
logger=_LOGGER,
|
logger=_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
name=f"{host}:{port}",
|
name=f"{host}:{port}",
|
||||||
update_interval=None, # Disable update interval as server pushes
|
update_interval=None, # Disable update interval as server pushes
|
||||||
)
|
)
|
||||||
|
|
||||||
self._server = Snapserver(hass.loop, host, port, True)
|
self._server = Snapserver(hass.loop, host, port, True)
|
||||||
self.last_update_success = False
|
self.last_update_success = False
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user