2019-02-13 21:21:14 +01:00
|
|
|
"""Support for Ecovacs Deebot vacuums."""
|
2018-08-20 17:42:53 +02:00
|
|
|
import logging
|
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
2019-11-26 03:01:48 +01:00
|
|
|
from sucks import EcoVacsAPI, VacBot
|
2018-08-20 17:42:53 +02:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
|
2018-08-20 17:42:53 +02:00
|
|
|
from homeassistant.helpers import discovery
|
2019-02-13 21:21:14 +01:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2018-08-20 17:42:53 +02:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DOMAIN = "ecovacs"
|
|
|
|
|
|
|
|
CONF_COUNTRY = "country"
|
|
|
|
CONF_CONTINENT = "continent"
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{
|
|
|
|
DOMAIN: vol.Schema(
|
|
|
|
{
|
|
|
|
vol.Required(CONF_USERNAME): cv.string,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
vol.Required(CONF_COUNTRY): vol.All(vol.Lower, cv.string),
|
|
|
|
vol.Required(CONF_CONTINENT): vol.All(vol.Lower, cv.string),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
},
|
|
|
|
extra=vol.ALLOW_EXTRA,
|
|
|
|
)
|
2018-08-20 17:42:53 +02:00
|
|
|
|
|
|
|
ECOVACS_DEVICES = "ecovacs_devices"
|
|
|
|
|
|
|
|
# Generate a random device ID on each bootup
|
2019-07-31 21:25:30 +02:00
|
|
|
ECOVACS_API_DEVICEID = "".join(
|
2018-08-20 17:42:53 +02:00
|
|
|
random.choice(string.ascii_uppercase + string.digits) for _ in range(8)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def setup(hass, config):
|
|
|
|
"""Set up the Ecovacs component."""
|
|
|
|
_LOGGER.debug("Creating new Ecovacs component")
|
|
|
|
|
|
|
|
hass.data[ECOVACS_DEVICES] = []
|
|
|
|
|
2019-07-31 21:25:30 +02:00
|
|
|
ecovacs_api = EcoVacsAPI(
|
|
|
|
ECOVACS_API_DEVICEID,
|
|
|
|
config[DOMAIN].get(CONF_USERNAME),
|
|
|
|
EcoVacsAPI.md5(config[DOMAIN].get(CONF_PASSWORD)),
|
|
|
|
config[DOMAIN].get(CONF_COUNTRY),
|
|
|
|
config[DOMAIN].get(CONF_CONTINENT),
|
|
|
|
)
|
2018-08-20 17:42:53 +02:00
|
|
|
|
|
|
|
devices = ecovacs_api.devices()
|
|
|
|
_LOGGER.debug("Ecobot devices: %s", devices)
|
|
|
|
|
|
|
|
for device in devices:
|
2018-09-18 08:30:20 +02:00
|
|
|
_LOGGER.info(
|
|
|
|
"Discovered Ecovacs device on account: %s with nickname %s",
|
2021-07-07 20:18:43 +02:00
|
|
|
device.get("did"),
|
|
|
|
device.get("nick"),
|
2019-07-31 21:25:30 +02:00
|
|
|
)
|
|
|
|
vacbot = VacBot(
|
|
|
|
ecovacs_api.uid,
|
|
|
|
ecovacs_api.REALM,
|
|
|
|
ecovacs_api.resource,
|
|
|
|
ecovacs_api.user_access_token,
|
|
|
|
device,
|
|
|
|
config[DOMAIN].get(CONF_CONTINENT).lower(),
|
|
|
|
monitor=True,
|
|
|
|
)
|
2018-08-20 17:42:53 +02:00
|
|
|
hass.data[ECOVACS_DEVICES].append(vacbot)
|
|
|
|
|
|
|
|
def stop(event: object) -> None:
|
|
|
|
"""Shut down open connections to Ecovacs XMPP server."""
|
|
|
|
for device in hass.data[ECOVACS_DEVICES]:
|
2019-07-31 21:25:30 +02:00
|
|
|
_LOGGER.info(
|
2021-07-07 20:18:43 +02:00
|
|
|
"Shutting down connection to Ecovacs device %s",
|
|
|
|
device.vacuum.get("did"),
|
2019-07-31 21:25:30 +02:00
|
|
|
)
|
2018-08-20 17:42:53 +02:00
|
|
|
device.disconnect()
|
|
|
|
|
|
|
|
# Listen for HA stop to disconnect.
|
|
|
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop)
|
|
|
|
|
|
|
|
if hass.data[ECOVACS_DEVICES]:
|
|
|
|
_LOGGER.debug("Starting vacuum components")
|
|
|
|
discovery.load_platform(hass, "vacuum", DOMAIN, {}, config)
|
|
|
|
|
|
|
|
return True
|