core/homeassistant/components/litterrobot/__init__.py

39 lines
1.2 KiB
Python
Raw Normal View History

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
PLATFORMS = ["select", "sensor", "switch", "vacuum"]
2021-02-22 18:53:57 +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."""
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
if hub.account.robots:
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
2021-02-22 18:53:57 +00:00
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
2021-02-22 18:53:57 +00:00
"""Unload a config entry."""
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