Don't block HA startup while set up legacy Ecovacs bot (#122732)

wait for connection in background
This commit is contained in:
Michael 2024-07-29 11:24:14 +02:00 committed by GitHub
parent 5f5dcec0b9
commit 686598b6b3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,6 @@
"""Support for Ecovacs Deebot vacuums."""
from sucks import VacBot
import voluptuous as vol
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
@ -61,6 +62,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: EcovacsConfigEntry) -> b
entry.async_on_unload(on_unload)
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

View File

@ -56,9 +56,9 @@ async def async_setup_entry(
for device in controller.devices
if device.capabilities.device_type is DeviceType.VACUUM
]
for device in controller.legacy_devices:
await hass.async_add_executor_job(device.connect_and_wait_until_ready)
vacuums.append(EcovacsLegacyVacuum(device))
vacuums.extend(
[EcovacsLegacyVacuum(device) for device in controller.legacy_devices]
)
_LOGGER.debug("Adding Ecovacs Vacuums to Home Assistant: %s", vacuums)
async_add_entities(vacuums)
@ -142,6 +142,11 @@ class EcovacsLegacyVacuum(EcovacsLegacyEntity, StateVacuumEntity):
return None
@property
def available(self) -> bool:
"""Return True if the vacuum is available."""
return super().available and self.state is not None
@property
def battery_level(self) -> int | None:
"""Return the battery level of the vacuum cleaner."""