mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Don't block HA startup while set up legacy Ecovacs bot (#122732)
wait for connection in background
This commit is contained in:
parent
5f5dcec0b9
commit
686598b6b3
@ -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
|
||||
|
||||
|
@ -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."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user