mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use runtime_data in frontier_silicon (#137633)
This commit is contained in:
parent
f06d209b2d
commit
60fd07f501
@ -11,14 +11,18 @@ from homeassistant.const import CONF_PIN, Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
|
|
||||||
from .const import CONF_WEBFSAPI_URL, DOMAIN
|
from .const import CONF_WEBFSAPI_URL
|
||||||
|
|
||||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type FrontierSiliconConfigEntry = ConfigEntry[AFSAPI]
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant, entry: FrontierSiliconConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Set up Frontier Silicon from a config entry."""
|
"""Set up Frontier Silicon from a config entry."""
|
||||||
|
|
||||||
webfsapi_url = entry.data[CONF_WEBFSAPI_URL]
|
webfsapi_url = entry.data[CONF_WEBFSAPI_URL]
|
||||||
@ -31,16 +35,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
except FSConnectionError as exception:
|
except FSConnectionError as exception:
|
||||||
raise ConfigEntryNotReady from exception
|
raise ConfigEntryNotReady from exception
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = afsapi
|
entry.runtime_data = afsapi
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(
|
||||||
|
hass: HomeAssistant, entry: FrontierSiliconConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
@ -20,11 +20,11 @@ from homeassistant.components.media_player import (
|
|||||||
MediaPlayerState,
|
MediaPlayerState,
|
||||||
MediaType,
|
MediaType,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from . import FrontierSiliconConfigEntry
|
||||||
from .browse_media import browse_node, browse_top_level
|
from .browse_media import browse_node, browse_top_level
|
||||||
from .const import DOMAIN, MEDIA_CONTENT_ID_PRESET
|
from .const import DOMAIN, MEDIA_CONTENT_ID_PRESET
|
||||||
|
|
||||||
@ -33,12 +33,12 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: FrontierSiliconConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Frontier Silicon entity."""
|
"""Set up the Frontier Silicon entity."""
|
||||||
|
|
||||||
afsapi: AFSAPI = hass.data[DOMAIN][config_entry.entry_id]
|
afsapi = config_entry.runtime_data
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
Loading…
x
Reference in New Issue
Block a user