mirror of
https://github.com/home-assistant/core.git
synced 2026-04-25 21:17:23 +00:00
Use runtime_data in volumio integration (#168616)
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
"""The Volumio integration."""
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from pyvolumio import CannotConnectError, Volumio
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@@ -8,12 +11,21 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DATA_INFO, DATA_VOLUMIO, DOMAIN
|
||||
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
@dataclass
|
||||
class VolumioData:
|
||||
"""Volumio data class."""
|
||||
|
||||
volumio: Volumio
|
||||
info: dict[str, Any]
|
||||
|
||||
|
||||
type VolumioConfigEntry = ConfigEntry[VolumioData]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: VolumioConfigEntry) -> bool:
|
||||
"""Set up Volumio from a config entry."""
|
||||
|
||||
volumio = Volumio(
|
||||
@@ -24,20 +36,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
except CannotConnectError as error:
|
||||
raise ConfigEntryNotReady from error
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
|
||||
DATA_VOLUMIO: volumio,
|
||||
DATA_INFO: info,
|
||||
}
|
||||
entry.runtime_data = VolumioData(volumio=volumio, info=info)
|
||||
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: VolumioConfigEntry) -> bool:
|
||||
"""Unload a config entry."""
|
||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
if unload_ok:
|
||||
hass.data[DOMAIN].pop(entry.entry_id)
|
||||
|
||||
return unload_ok
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
"""Constants for the Volumio integration."""
|
||||
|
||||
DOMAIN = "volumio"
|
||||
|
||||
DATA_INFO = "info"
|
||||
DATA_VOLUMIO = "volumio"
|
||||
|
||||
@@ -17,29 +17,29 @@ from homeassistant.components.media_player import (
|
||||
MediaType,
|
||||
RepeatMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_ID, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.util import Throttle
|
||||
|
||||
from . import VolumioConfigEntry
|
||||
from .browse_media import browse_node, browse_top_level
|
||||
from .const import DATA_INFO, DATA_VOLUMIO, DOMAIN
|
||||
from .const import DOMAIN
|
||||
|
||||
PLAYLIST_UPDATE_INTERVAL = timedelta(seconds=15)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
config_entry: VolumioConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Volumio media player platform."""
|
||||
|
||||
data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
volumio = data[DATA_VOLUMIO]
|
||||
info = data[DATA_INFO]
|
||||
data = config_entry.runtime_data
|
||||
volumio = data.volumio
|
||||
info = data.info
|
||||
uid = config_entry.data[CONF_ID]
|
||||
name = config_entry.data[CONF_NAME]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user