Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions tests/devices/test_device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,30 +279,32 @@ async def test_start_connect_failure(
fake_device.local_channel.inject_error(channel_exception)

ready_devices: list[RoborockDevice] = []
device_manager = await create_device_manager(USER_PARAMS, ready_callback=ready_devices.append)
devices = await device_manager.get_devices()
ready = asyncio.Event()

# Device should exist but not be connected
assert len(devices) == 1
assert not devices[0].is_connected
assert not ready_devices

# Clear error so connection succeeds on retry
fake_device.mqtt_channel.clear_error()
fake_device.local_channel.clear_error()

# Wait for the device to attempt to connect again and succeed
attempts = 0
while not devices[0].is_connected:
await asyncio.sleep(0.01)
attempts += 1
assert attempts < 10, "Device did not connect after multiple attempts"

assert devices[0].is_connected
assert ready_devices
assert len(ready_devices) == 1
def on_ready(device: RoborockDevice) -> None:
ready_devices.append(device)
ready.set()

await device_manager.close()
device_manager = await create_device_manager(USER_PARAMS, ready_callback=on_ready)
try:
devices = await device_manager.get_devices()

# Device should exist but not be connected
assert len(devices) == 1
assert not devices[0].is_connected
assert not ready_devices

# Clear error so connection succeeds on retry
fake_device.mqtt_channel.clear_error()
fake_device.local_channel.clear_error()

# Transport connection can precede initialization and the ready callback.
await asyncio.wait_for(ready.wait(), timeout=5)

assert devices[0].is_connected
assert ready_devices == devices
finally:
await device_manager.close()


async def test_rediscover_devices(
Expand Down
Loading