mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Use runtime_data in epson (#136706)
This commit is contained in:
parent
f14f7936eb
commit
933aec1027
@ -13,13 +13,15 @@ from homeassistant.const import CONF_HOST, Platform
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
|
||||||
from .const import CONF_CONNECTION_TYPE, DOMAIN, HTTP
|
from .const import CONF_CONNECTION_TYPE, HTTP
|
||||||
from .exceptions import CannotConnect, PoweredOff
|
from .exceptions import CannotConnect, PoweredOff
|
||||||
|
|
||||||
PLATFORMS = [Platform.MEDIA_PLAYER]
|
PLATFORMS = [Platform.MEDIA_PLAYER]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
type EpsonConfigEntry = ConfigEntry[Projector]
|
||||||
|
|
||||||
|
|
||||||
async def validate_projector(
|
async def validate_projector(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@ -45,7 +47,7 @@ async def validate_projector(
|
|||||||
return epson_proj
|
return epson_proj
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: EpsonConfigEntry) -> bool:
|
||||||
"""Set up epson from a config entry."""
|
"""Set up epson from a config entry."""
|
||||||
projector = await validate_projector(
|
projector = await validate_projector(
|
||||||
hass=hass,
|
hass=hass,
|
||||||
@ -54,23 +56,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
check_power=False,
|
check_power=False,
|
||||||
check_powered_on=False,
|
check_powered_on=False,
|
||||||
)
|
)
|
||||||
hass.data.setdefault(DOMAIN, {})
|
entry.runtime_data = projector
|
||||||
hass.data[DOMAIN][entry.entry_id] = projector
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
entry.async_on_unload(projector.close)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: EpsonConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
|
||||||
projector = hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
projector.close()
|
|
||||||
return unload_ok
|
|
||||||
|
|
||||||
|
|
||||||
async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_migrate_entry(
|
||||||
|
hass: HomeAssistant, config_entry: EpsonConfigEntry
|
||||||
|
) -> bool:
|
||||||
"""Migrate old entry."""
|
"""Migrate old entry."""
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Migrating configuration from version %s.%s",
|
"Migrating configuration from version %s.%s",
|
||||||
|
@ -45,6 +45,7 @@ from homeassistant.helpers import (
|
|||||||
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 EpsonConfigEntry
|
||||||
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
|
from .const import ATTR_CMODE, DOMAIN, SERVICE_SELECT_CMODE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -52,13 +53,12 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: EpsonConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Epson projector from a config entry."""
|
"""Set up the Epson projector from a config entry."""
|
||||||
projector: Projector = hass.data[DOMAIN][config_entry.entry_id]
|
|
||||||
projector_entity = EpsonProjectorMediaPlayer(
|
projector_entity = EpsonProjectorMediaPlayer(
|
||||||
projector=projector,
|
projector=config_entry.runtime_data,
|
||||||
unique_id=config_entry.unique_id or config_entry.entry_id,
|
unique_id=config_entry.unique_id or config_entry.entry_id,
|
||||||
entry=config_entry,
|
entry=config_entry,
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user