2021-03-21 17:41:41 +00:00
|
|
|
"""Support for Deebot Vaccums."""
|
|
|
|
import logging
|
2021-08-28 19:21:19 +00:00
|
|
|
import asyncio
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from . import hub
|
|
|
|
from .const import DOMAIN, STARTUP
|
2021-03-21 17:41:41 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
PLATFORMS = ["sensor", "binary_sensor", "vacuum", "camera"]
|
2021-03-21 17:41:41 +00:00
|
|
|
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
async def async_setup(hass: HomeAssistant, config: dict):
|
|
|
|
"""Set up the Deebot component."""
|
|
|
|
# Ensure our name space for storing objects is a known type. A dict is
|
|
|
|
# common/preferred as it allows a separate instance of your class for each
|
|
|
|
# instance that has been created in the UI.
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
2021-03-21 17:41:41 +00:00
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
# Print startup message
|
|
|
|
_LOGGER.info(STARTUP)
|
2021-03-21 17:41:41 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
# Store an instance of the "connecting" class that does the work of speaking
|
|
|
|
# with your actual devices.
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = await hass.async_add_executor_job(
|
|
|
|
hub.DeebotHub, hass, entry.data
|
|
|
|
)
|
2021-03-21 17:41:41 +00:00
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
# This creates each HA object for each platform your device requires.
|
|
|
|
# It's done by calling the `async_setup_entry` function in each platform module.
|
|
|
|
for component in PLATFORMS:
|
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.async_forward_entry_setup(entry, component)
|
|
|
|
)
|
2021-03-21 17:41:41 +00:00
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
return True
|
2021-03-21 17:41:41 +00:00
|
|
|
|
|
|
|
|
2021-08-28 19:21:19 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|
|
|
"""Unload a config entry."""
|
|
|
|
# This is called when an entry/configured device is to be removed. The class
|
|
|
|
# needs to unload itself, and remove callbacks. See the classes for further
|
|
|
|
# details
|
|
|
|
unload_ok = all(
|
|
|
|
await asyncio.gather(
|
|
|
|
*[
|
|
|
|
hass.config_entries.async_forward_entry_unload(entry, component)
|
|
|
|
for component in PLATFORMS
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN][entry.entry_id].disconnect()
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|