2021-02-22 18:53:57 +00:00
|
|
|
"""The Litter-Robot integration."""
|
|
|
|
|
|
|
|
from pylitterbot.exceptions import LitterRobotException, LitterRobotLoginException
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
from .hub import LitterRobotHub
|
|
|
|
|
2021-10-29 12:47:15 +00:00
|
|
|
PLATFORMS = ["select", "sensor", "switch", "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)
|
|
|
|
try:
|
|
|
|
await hub.login(load_robots=True)
|
|
|
|
except LitterRobotLoginException:
|
|
|
|
return False
|
|
|
|
except LitterRobotException as ex:
|
|
|
|
raise ConfigEntryNotReady from ex
|
|
|
|
|
2021-04-11 20:35:25 +00:00
|
|
|
if hub.account.robots:
|
2021-04-27 16:49:13 +00:00
|
|
|
hass.config_entries.async_setup_platforms(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)
|
2021-02-22 18:53:57 +00:00
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|