2021-07-21 11:31:54 +00:00
|
|
|
"""The NFAndroidTV integration."""
|
|
|
|
from notifications_android_tv.notifications import ConnectError, Notifications
|
|
|
|
|
2022-06-09 09:06:59 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_HOST, Platform
|
2021-07-21 11:31:54 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
from homeassistant.helpers import discovery
|
2022-06-09 09:06:59 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2021-08-18 11:22:05 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2021-07-21 11:31:54 +00:00
|
|
|
|
2022-06-09 09:06:59 +00:00
|
|
|
from .const import DATA_HASS_CONFIG, DOMAIN
|
2021-07-21 11:31:54 +00:00
|
|
|
|
2022-01-09 06:57:51 +00:00
|
|
|
PLATFORMS = [Platform.NOTIFY]
|
2021-07-21 11:31:54 +00:00
|
|
|
|
2022-06-09 09:06:59 +00:00
|
|
|
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
|
|
|
|
2021-07-21 11:31:54 +00:00
|
|
|
|
2021-08-18 11:22:05 +00:00
|
|
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
2021-07-21 11:31:54 +00:00
|
|
|
"""Set up the NFAndroidTV component."""
|
|
|
|
|
2022-06-09 09:06:59 +00:00
|
|
|
hass.data[DATA_HASS_CONFIG] = config
|
2021-07-21 11:31:54 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Set up NFAndroidTV from a config entry."""
|
|
|
|
try:
|
2022-06-09 09:06:59 +00:00
|
|
|
await hass.async_add_executor_job(Notifications, entry.data[CONF_HOST])
|
2021-07-21 11:31:54 +00:00
|
|
|
except ConnectError as ex:
|
2022-06-09 09:06:59 +00:00
|
|
|
raise ConfigEntryNotReady(
|
|
|
|
f"Failed to connect to host: {entry.data[CONF_HOST]}"
|
|
|
|
) from ex
|
2021-07-21 11:31:54 +00:00
|
|
|
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
|
|
|
|
hass.async_create_task(
|
|
|
|
discovery.async_load_platform(
|
2022-01-09 06:57:51 +00:00
|
|
|
hass,
|
|
|
|
Platform.NOTIFY,
|
|
|
|
DOMAIN,
|
2022-06-09 09:06:59 +00:00
|
|
|
dict(entry.data),
|
|
|
|
hass.data[DATA_HASS_CONFIG],
|
2021-07-21 11:31:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Unload a config entry."""
|
2022-06-09 09:06:59 +00:00
|
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|