revert async to push minimal change update for release
has StateVacuumEntity but no async, will push release like this that should work and push another release with async
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
"""Support for Ecovacs Deebot vacuums."""
|
"""Support for Ecovacs Deebot vacuums."""
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
@@ -44,60 +45,55 @@ ECOVACS_API_DEVICEID = "".join(
|
|||||||
random.choice(string.ascii_uppercase + string.digits) for _ in range(8)
|
random.choice(string.ascii_uppercase + string.digits) for _ in range(8)
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Ecovacs component."""
|
"""Set up the Ecovacs component."""
|
||||||
LOGGER.debug("Creating new Ecovacs component")
|
LOGGER.debug("Creating new Ecovacs component")
|
||||||
def get_devices() -> list[VacBot]:
|
hass.data[ECOVACS_DEVICES] = []
|
||||||
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),
|
|
||||||
)
|
|
||||||
ecovacs_devices = ecovacs_api.devices()
|
|
||||||
_LOGGER.debug("Ecobot devices: %s", ecovacs_devices)
|
|
||||||
|
|
||||||
SERVER_ADDRESS = None
|
SERVER_ADDRESS = None
|
||||||
|
|
||||||
devices: list[VacBot] = []
|
ecovacs_api = EcoVacsAPI(
|
||||||
for device in ecovacs_devices:
|
ECOVACS_API_DEVICEID,
|
||||||
_LOGGER.info(
|
config[DOMAIN].get(CONF_USERNAME),
|
||||||
"Discovered Ecovacs device on account: %s with nickname %s",
|
EcoVacsAPI.md5(config[DOMAIN].get(CONF_PASSWORD)),
|
||||||
device.get("did"),
|
config[DOMAIN].get(CONF_COUNTRY),
|
||||||
device.get("nick"),
|
config[DOMAIN].get(CONF_CONTINENT),
|
||||||
)
|
config[DOMAIN].get(CONF_VERIFY_SSL), # add to class call
|
||||||
vacbot = VacBot(
|
)
|
||||||
ecovacs_api.uid,
|
|
||||||
ecovacs_api.REALM,
|
|
||||||
ecovacs_api.resource,
|
|
||||||
ecovacs_api.user_access_token,
|
|
||||||
device,
|
|
||||||
config[DOMAIN].get(CONF_CONTINENT).lower(),
|
|
||||||
config[DOMAIN].get(CONF_VERIFY_SSL), # add to class call
|
|
||||||
monitor=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
devices.append(vacbot)
|
devices = ecovacs_api.devices()
|
||||||
return devices
|
LOGGER.debug("Ecobot devices: %s", devices)
|
||||||
|
|
||||||
hass.data[ECOVACS_DEVICES] = await hass.async_add_executor_job(get_devices)
|
for device in devices:
|
||||||
|
LOGGER.info(
|
||||||
|
"Discovered Ecovacs device on account: %s with nickname %s",
|
||||||
|
device.get("did"),
|
||||||
|
device.get("nick"),
|
||||||
|
)
|
||||||
|
vacbot = VacBot(
|
||||||
|
ecovacs_api.uid,
|
||||||
|
ecovacs_api.REALM,
|
||||||
|
ecovacs_api.resource,
|
||||||
|
ecovacs_api.user_access_token,
|
||||||
|
device,
|
||||||
|
config[DOMAIN].get(CONF_CONTINENT).lower(),
|
||||||
|
SERVER_ADDRESS, # include server address in class, if it's null should be no effect
|
||||||
|
config[DOMAIN].get(CONF_VERIFY_SSL), # add to class call
|
||||||
|
monitor=True
|
||||||
|
)
|
||||||
|
hass.data[ECOVACS_DEVICES].append(vacbot)
|
||||||
|
|
||||||
async def async_stop(event: object) -> None:
|
def stop(event: object) -> None:
|
||||||
"""Shut down open connections to Ecovacs XMPP server."""
|
"""Shut down open connections to Ecovacs XMPP server."""
|
||||||
devices: list[VacBot] = hass.data[ECOVACS_DEVICES]
|
for device in hass.data[ECOVACS_DEVICES]:
|
||||||
for device in devices:
|
|
||||||
LOGGER.info(
|
LOGGER.info(
|
||||||
"Shutting down connection to Ecovacs device %s",
|
"Shutting down connection to Ecovacs device %s",
|
||||||
device.vacuum.get("did"),
|
device.vacuum.get("did"),
|
||||||
)
|
)
|
||||||
await hass.async_add_executor_job(device.disconnect)
|
device.disconnect()
|
||||||
|
|
||||||
# Listen for HA stop to disconnect.
|
# Listen for HA stop to disconnect.
|
||||||
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop)
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop)
|
||||||
if hass.data[ECOVACS_DEVICES]:
|
if hass.data[ECOVACS_DEVICES]:
|
||||||
LOGGER.debug("Starting vacuum components")
|
LOGGER.debug("Starting vacuum components")
|
||||||
hass.async_create_task(
|
discovery.load_platform(hass, Platform.VACUUM, DOMAIN, {}, config)
|
||||||
discovery.async_load_platform(hass, Platform.VACUUM, DOMAIN, {}, config)
|
|
||||||
)
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -21,20 +21,18 @@ ATTR_ERROR = "error"
|
|||||||
ATTR_COMPONENT_PREFIX = "component_"
|
ATTR_COMPONENT_PREFIX = "component_"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
def setup_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
async_add_entities: AddEntitiesCallback,
|
add_entities: AddEntitiesCallback,
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Ecovacs vacuums."""
|
"""Set up the Ecovacs vacuums."""
|
||||||
vacuums = []
|
vacuums = []
|
||||||
devices: list[sucks.VacBot] = hass.data[ECOVACS_DEVICES]
|
for device in hass.data[ECOVACS_DEVICES]:
|
||||||
for device in devices:
|
|
||||||
await hass.async_add_executor_job(device.connect_and_wait_until_ready)
|
|
||||||
vacuums.append(EcovacsVacuum(device))
|
vacuums.append(EcovacsVacuum(device))
|
||||||
_LOGGER.debug("Adding Ecovacs Vacuums to Home Assistant: %s", vacuums)
|
_LOGGER.debug("Adding Ecovacs Vacuums to Home Assistant: %s", vacuums)
|
||||||
async_add_entities(vacuums)
|
add_entities(vacuums, True)
|
||||||
|
|
||||||
|
|
||||||
class EcovacsVacuum(StateVacuumEntity):
|
class EcovacsVacuum(StateVacuumEntity):
|
||||||
@@ -58,7 +56,7 @@ class EcovacsVacuum(StateVacuumEntity):
|
|||||||
def __init__(self, device: sucks.VacBot) -> None:
|
def __init__(self, device: sucks.VacBot) -> None:
|
||||||
"""Initialize the Ecovacs Vacuum."""
|
"""Initialize the Ecovacs Vacuum."""
|
||||||
self.device = device
|
self.device = device
|
||||||
|
self.device.connect_and_wait_until_ready()
|
||||||
if self.device.vacuum.get("nick") is not None:
|
if self.device.vacuum.get("nick") is not None:
|
||||||
self._attr_name = str(self.device.vacuum["nick"])
|
self._attr_name = str(self.device.vacuum["nick"])
|
||||||
else:
|
else:
|
||||||
@@ -66,6 +64,7 @@ class EcovacsVacuum(StateVacuumEntity):
|
|||||||
self._attr_name = str(format(self.device.vacuum["did"]))
|
self._attr_name = str(format(self.device.vacuum["did"]))
|
||||||
|
|
||||||
self._error = None
|
self._error = None
|
||||||
|
_LOGGER.debug("Vacuum initialized: %s", self.name)
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Set up the event listeners now that hass is ready."""
|
"""Set up the event listeners now that hass is ready."""
|
||||||
|
|||||||
Reference in New Issue
Block a user