2021-02-22 18:53:57 +00:00
|
|
|
"""The Litter-Robot integration."""
|
2022-07-25 20:52:13 +00:00
|
|
|
from __future__ import annotations
|
2021-02-22 18:53:57 +00:00
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-06 03:10:07 +00:00
|
|
|
from homeassistant.const import Platform
|
2021-02-22 18:53:57 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
from .hub import LitterRobotHub
|
|
|
|
|
2021-12-06 03:10:07 +00:00
|
|
|
PLATFORMS = [
|
|
|
|
Platform.BUTTON,
|
|
|
|
Platform.SELECT,
|
|
|
|
Platform.SENSOR,
|
|
|
|
Platform.SWITCH,
|
|
|
|
Platform.VACUUM,
|
|
|
|
]
|
2021-02-22 18:53:57 +00:00
|
|
|
|
|
|
|
|
2021-05-27 15:39:06 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2021-02-22 18:53:57 +00:00
|
|
|
"""Set up Litter-Robot from a config entry."""
|
2021-04-16 16:23:27 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})
|
2021-02-22 18:53:57 +00:00
|
|
|
hub = hass.data[DOMAIN][entry.entry_id] = LitterRobotHub(hass, entry.data)
|
2022-08-29 04:40:28 +00:00
|
|
|
await hub.login(load_robots=True)
|
2021-02-22 18:53:57 +00:00
|
|
|
|
2022-08-25 16:32:27 +00:00
|
|
|
if any(hub.litter_robots()):
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
2021-02-22 18:53:57 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-10-06 08:48:11 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2021-02-22 18:53:57 +00:00
|
|
|
"""Unload a config entry."""
|
2021-04-27 16:49:13 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
2022-08-25 16:32:27 +00:00
|
|
|
|
|
|
|
hub: LitterRobotHub = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
await hub.account.disconnect()
|
|
|
|
|
2021-02-22 18:53:57 +00:00
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|