Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The DirecTV integration."""
2 
3 from __future__ import annotations
4 
5 from datetime import timedelta
6 
7 from directv import DIRECTV, DIRECTVError
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.const import CONF_HOST, Platform
11 from homeassistant.core import HomeAssistant
12 from homeassistant.exceptions import ConfigEntryNotReady
13 from homeassistant.helpers.aiohttp_client import async_get_clientsession
14 
15 from .const import DOMAIN
16 
17 PLATFORMS = [Platform.MEDIA_PLAYER, Platform.REMOTE]
18 SCAN_INTERVAL = timedelta(seconds=30)
19 
20 
21 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
22  """Set up DirecTV from a config entry."""
23  dtv = DIRECTV(entry.data[CONF_HOST], session=async_get_clientsession(hass))
24 
25  try:
26  await dtv.update()
27  except DIRECTVError as err:
28  raise ConfigEntryNotReady from err
29 
30  hass.data.setdefault(DOMAIN, {})
31  hass.data[DOMAIN][entry.entry_id] = dtv
32 
33  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
34 
35  return True
36 
37 
38 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
39  """Unload a config entry."""
40  unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
41  if unload_ok:
42  hass.data[DOMAIN].pop(entry.entry_id)
43 
44  return unload_ok
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:38
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:21
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)