2021-08-24 19:09:36 +00:00
|
|
|
"""The Nanoleaf integration."""
|
2021-09-23 20:37:37 +00:00
|
|
|
from aionanoleaf import InvalidToken, Nanoleaf, Unavailable
|
2021-08-24 19:09:36 +00:00
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_TOKEN
|
|
|
|
from homeassistant.core import HomeAssistant
|
2021-08-25 19:56:10 +00:00
|
|
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
2021-09-23 20:37:37 +00:00
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
2021-08-24 19:09:36 +00:00
|
|
|
|
2021-09-28 20:39:54 +00:00
|
|
|
from .const import DOMAIN
|
2021-08-24 19:09:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Set up Nanoleaf from a config entry."""
|
2021-09-23 20:37:37 +00:00
|
|
|
nanoleaf = Nanoleaf(
|
|
|
|
async_get_clientsession(hass), entry.data[CONF_HOST], entry.data[CONF_TOKEN]
|
|
|
|
)
|
2021-08-24 19:09:36 +00:00
|
|
|
try:
|
2021-09-23 20:37:37 +00:00
|
|
|
await nanoleaf.get_info()
|
2021-08-24 19:09:36 +00:00
|
|
|
except Unavailable as err:
|
|
|
|
raise ConfigEntryNotReady from err
|
2021-08-25 19:56:10 +00:00
|
|
|
except InvalidToken as err:
|
|
|
|
raise ConfigEntryAuthFailed from err
|
2021-08-24 19:09:36 +00:00
|
|
|
|
2021-09-28 20:39:54 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = nanoleaf
|
2021-08-24 19:09:36 +00:00
|
|
|
|
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.async_forward_entry_setup(entry, "light")
|
|
|
|
)
|
|
|
|
return True
|