2020-03-11 19:28:38 +00:00
|
|
|
"""The DirecTV integration."""
|
2021-03-17 22:43:55 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-03-11 19:28:38 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2020-03-31 22:35:32 +00:00
|
|
|
from directv import DIRECTV, DIRECTVError
|
2020-03-11 19:28:38 +00:00
|
|
|
|
2020-10-29 08:51:22 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-03 16:51:30 +00:00
|
|
|
from homeassistant.const import CONF_HOST, Platform
|
2020-03-11 19:28:38 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
from homeassistant.helpers import config_validation as cv
|
2020-03-31 22:35:32 +00:00
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
|
2021-06-23 14:10:29 +00:00
|
|
|
from .const import DOMAIN
|
2020-03-11 19:28:38 +00:00
|
|
|
|
2021-12-21 11:46:10 +00:00
|
|
|
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
2020-03-11 19:28:38 +00:00
|
|
|
|
2021-12-03 16:51:30 +00:00
|
|
|
PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE]
|
2020-03-11 19:28:38 +00:00
|
|
|
SCAN_INTERVAL = timedelta(seconds=30)
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Set up DirecTV from a config entry."""
|
2020-03-31 22:35:32 +00:00
|
|
|
dtv = DIRECTV(entry.data[CONF_HOST], session=async_get_clientsession(hass))
|
|
|
|
|
2020-03-11 19:28:38 +00:00
|
|
|
try:
|
2020-03-31 22:35:32 +00:00
|
|
|
await dtv.update()
|
2020-08-28 11:50:32 +00:00
|
|
|
except DIRECTVError as err:
|
|
|
|
raise ConfigEntryNotReady from err
|
2020-03-11 19:28:38 +00:00
|
|
|
|
2021-03-29 23:23:44 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})
|
2020-03-31 22:35:32 +00:00
|
|
|
hass.data[DOMAIN][entry.entry_id] = dtv
|
2020-03-11 19:28:38 +00:00
|
|
|
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
2020-03-11 19:28:38 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Unload a config entry."""
|
2021-04-27 06:46:49 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
2020-03-11 19:28:38 +00:00
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|