Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The NFAndroidTV integration."""
2 
3 from notifications_android_tv.notifications import ConnectError, Notifications
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_HOST, Platform
7 from homeassistant.core import HomeAssistant
8 from homeassistant.exceptions import ConfigEntryNotReady
9 from homeassistant.helpers import discovery
11 from homeassistant.helpers.typing import ConfigType
12 
13 from .const import DATA_HASS_CONFIG, DOMAIN
14 
15 PLATFORMS = [Platform.NOTIFY]
16 
17 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
18 
19 
20 async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
21  """Set up the NFAndroidTV component."""
22 
23  hass.data[DATA_HASS_CONFIG] = config
24  return True
25 
26 
27 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
28  """Set up NFAndroidTV from a config entry."""
29  try:
30  await hass.async_add_executor_job(Notifications, entry.data[CONF_HOST])
31  except ConnectError as ex:
32  raise ConfigEntryNotReady(
33  f"Failed to connect to host: {entry.data[CONF_HOST]}"
34  ) from ex
35 
36  hass.data.setdefault(DOMAIN, {})
37 
38  hass.async_create_task(
39  discovery.async_load_platform(
40  hass,
41  Platform.NOTIFY,
42  DOMAIN,
43  dict(entry.data),
44  hass.data[DATA_HASS_CONFIG],
45  )
46  )
47 
48  return True
49 
50 
51 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
52  """Unload a config entry."""
53  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:27
bool async_setup(HomeAssistant hass, ConfigType config)
Definition: __init__.py:20
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:51