2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Roku."""
|
2021-03-18 13:31:38 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-10-29 08:51:48 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-04 12:19:49 +00:00
|
|
|
from homeassistant.const import CONF_HOST, Platform
|
2021-04-22 17:58:02 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-03-16 04:13:04 +00:00
|
|
|
from homeassistant.helpers import config_validation as cv
|
2020-05-08 21:44:34 +00:00
|
|
|
|
2021-06-11 11:51:18 +00:00
|
|
|
from .const import DOMAIN
|
2021-07-05 08:27:52 +00:00
|
|
|
from .coordinator import RokuDataUpdateCoordinator
|
2019-01-14 07:44:30 +00:00
|
|
|
|
2021-12-21 11:46:10 +00:00
|
|
|
CONFIG_SCHEMA = cv.removed(DOMAIN, raise_if_present=False)
|
2019-01-14 07:44:30 +00:00
|
|
|
|
2022-01-17 02:39:18 +00:00
|
|
|
PLATFORMS = [
|
|
|
|
Platform.BINARY_SENSOR,
|
|
|
|
Platform.MEDIA_PLAYER,
|
|
|
|
Platform.REMOTE,
|
2022-02-12 02:52:31 +00:00
|
|
|
Platform.SELECT,
|
2022-01-17 02:39:18 +00:00
|
|
|
Platform.SENSOR,
|
|
|
|
]
|
2022-02-07 01:13:01 +00:00
|
|
|
|
2019-01-14 07:44:30 +00:00
|
|
|
|
2021-04-22 17:58:02 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-03-16 04:13:04 +00:00
|
|
|
"""Set up Roku from a config entry."""
|
2021-04-16 16:22:56 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})
|
2021-10-21 06:33:10 +00:00
|
|
|
if not (coordinator := hass.data[DOMAIN].get(entry.entry_id)):
|
2021-04-11 17:35:42 +00:00
|
|
|
coordinator = RokuDataUpdateCoordinator(hass, host=entry.data[CONF_HOST])
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = coordinator
|
2020-05-08 21:44:34 +00:00
|
|
|
|
2021-04-11 17:35:42 +00:00
|
|
|
await coordinator.async_config_entry_first_refresh()
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
2019-01-14 07:44:30 +00:00
|
|
|
|
2020-03-16 04:13:04 +00:00
|
|
|
return True
|
2019-01-14 07:44:30 +00:00
|
|
|
|
|
|
|
|
2021-04-22 17:58:02 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-03-16 04:13:04 +00:00
|
|
|
"""Unload a config entry."""
|
2021-04-27 20:10:04 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
2020-03-16 04:13:04 +00:00
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
return unload_ok
|