mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Use runtime_data in dunehd (#136443)
This commit is contained in:
parent
98e59f01b7
commit
51bc56929b
@ -10,29 +10,21 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
PLATFORMS: Final[list[Platform]] = [Platform.MEDIA_PLAYER]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
type DuneHDConfigEntry = ConfigEntry[DuneHDPlayer]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: DuneHDConfigEntry) -> bool:
|
||||
"""Set up a config entry."""
|
||||
host: str = entry.data[CONF_HOST]
|
||||
|
||||
player = DuneHDPlayer(host)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = player
|
||||
entry.runtime_data = DuneHDPlayer(entry.data[CONF_HOST])
|
||||
|
||||
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: DuneHDConfigEntry) -> 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)
|
||||
|
@ -15,11 +15,11 @@ from homeassistant.components.media_player import (
|
||||
MediaType,
|
||||
async_process_play_media_url,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import DuneHDConfigEntry
|
||||
from .const import ATTR_MANUFACTURER, DEFAULT_NAME, DOMAIN
|
||||
|
||||
CONF_SOURCES: Final = "sources"
|
||||
@ -37,14 +37,14 @@ DUNEHD_PLAYER_SUPPORT: Final[MediaPlayerEntityFeature] = (
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
hass: HomeAssistant,
|
||||
entry: DuneHDConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Add Dune HD entities from a config_entry."""
|
||||
unique_id = entry.entry_id
|
||||
|
||||
player: DuneHDPlayer = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
async_add_entities([DuneHDPlayerEntity(player, DEFAULT_NAME, unique_id)], True)
|
||||
async_add_entities(
|
||||
[DuneHDPlayerEntity(entry.runtime_data, DEFAULT_NAME, entry.entry_id)], True
|
||||
)
|
||||
|
||||
|
||||
class DuneHDPlayerEntity(MediaPlayerEntity):
|
||||
|
Loading…
x
Reference in New Issue
Block a user