1
0
mirror of https://github.com/home-assistant/core.git synced 2026-03-03 08:10:36 +00:00
Files
core/homeassistant/components/ecovacs/__init__.py

64 lines
1.9 KiB
Python

"""Support for Ecovacs Deebot vacuums."""
from sucks import VacBot
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.typing import ConfigType
from .const import DOMAIN
from .controller import EcovacsController
from .services import async_setup_services
PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.EVENT,
Platform.IMAGE,
Platform.LAWN_MOWER,
Platform.NUMBER,
Platform.SELECT,
Platform.SENSOR,
Platform.SWITCH,
Platform.VACUUM,
]
type EcovacsConfigEntry = ConfigEntry[EcovacsController]
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the component."""
async_setup_services(hass)
return True
async def async_setup_entry(hass: HomeAssistant, entry: EcovacsConfigEntry) -> bool:
"""Set up this integration using UI."""
controller = EcovacsController(hass, entry.data)
entry.async_on_unload(controller.teardown)
await controller.initialize()
entry.runtime_data = controller
async def _async_wait_connect(device: VacBot) -> None:
await hass.async_add_executor_job(device.connect_and_wait_until_ready)
for device in controller.legacy_devices:
entry.async_create_background_task(
hass=hass,
target=_async_wait_connect(device),
name=f"{entry.title}_wait_connect_{device.vacuum['did']}",
)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: EcovacsConfigEntry) -> bool:
"""Unload config entry."""
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)