mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Use runtime_data in directv (#136435)
This commit is contained in:
parent
c991d4dac5
commit
384c173ab3
@ -12,13 +12,14 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE]
|
||||
SCAN_INTERVAL = timedelta(seconds=30)
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
type DirecTVConfigEntry = ConfigEntry[DIRECTV]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: DirecTVConfigEntry) -> bool:
|
||||
"""Set up DirecTV from a config entry."""
|
||||
dtv = DIRECTV(entry.data[CONF_HOST], session=async_get_clientsession(hass))
|
||||
|
||||
@ -27,18 +28,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
except DIRECTVError as err:
|
||||
raise ConfigEntryNotReady from err
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = dtv
|
||||
entry.runtime_data = dtv
|
||||
|
||||
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: DirecTVConfigEntry) -> 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)
|
||||
|
@ -14,17 +14,16 @@ from homeassistant.components.media_player import (
|
||||
MediaPlayerState,
|
||||
MediaType,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import DirecTVConfigEntry
|
||||
from .const import (
|
||||
ATTR_MEDIA_CURRENTLY_RECORDING,
|
||||
ATTR_MEDIA_RATING,
|
||||
ATTR_MEDIA_RECORDED,
|
||||
ATTR_MEDIA_START_TIME,
|
||||
DOMAIN,
|
||||
)
|
||||
from .entity import DIRECTVEntity
|
||||
|
||||
@ -55,11 +54,11 @@ SUPPORT_DTV_CLIENT = (
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DirecTVConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the DirecTV config entry."""
|
||||
dtv = hass.data[DOMAIN][entry.entry_id]
|
||||
dtv = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
(
|
||||
|
@ -10,11 +10,10 @@ from typing import Any
|
||||
from directv import DIRECTV, DIRECTVError
|
||||
|
||||
from homeassistant.components.remote import ATTR_NUM_REPEATS, RemoteEntity
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from . import DirecTVConfigEntry
|
||||
from .entity import DIRECTVEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@ -24,11 +23,11 @@ SCAN_INTERVAL = timedelta(minutes=2)
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
entry: DirecTVConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Load DirecTV remote based on a config entry."""
|
||||
dtv = hass.data[DOMAIN][entry.entry_id]
|
||||
dtv = entry.runtime_data
|
||||
|
||||
async_add_entities(
|
||||
(
|
||||
|
@ -1,6 +1,5 @@
|
||||
"""Tests for the DirecTV integration."""
|
||||
|
||||
from homeassistant.components.directv.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
@ -24,11 +23,9 @@ async def test_unload_config_entry(
|
||||
"""Test the DirecTV configuration entry unloading."""
|
||||
entry = await setup_integration(hass, aioclient_mock)
|
||||
|
||||
assert entry.entry_id in hass.data[DOMAIN]
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.entry_id not in hass.data[DOMAIN]
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
Loading…
x
Reference in New Issue
Block a user