|
9 | 9 | from roborock.devices.device_manager import UserParams, create_device_manager |
10 | 10 | from roborock.devices.traits.v1.consumeable import ConsumableAttribute |
11 | 11 | from roborock.exceptions import RoborockException |
12 | | -from roborock.testing import DEFAULT_STATUS, FakeRoborockCloud, V1VacuumSimulator |
| 12 | +from roborock.testing import ( |
| 13 | + DEFAULT_NETWORK_INFO, |
| 14 | + DEFAULT_STATUS, |
| 15 | + FakeRoborockCloud, |
| 16 | + V1VacuumSimulator, |
| 17 | +) |
13 | 18 | from tests import mock_data |
14 | 19 |
|
15 | 20 | USER_DATA = UserData.from_dict(mock_data.USER_DATA) |
@@ -208,3 +213,52 @@ async def test_trait_publish_failure_injection(): |
208 | 213 | fake_device.mqtt_channel.publish_side_effect = RoborockException("MQTT network error") |
209 | 214 | with pytest.raises(RoborockException, match="MQTT network error"): |
210 | 215 | await device.v1_properties.status.refresh() |
| 216 | + |
| 217 | + |
| 218 | +async def test_multiple_devices_network_info_override(): |
| 219 | + """Verify that multiple devices can coexist and their individual custom network |
| 220 | +
|
| 221 | + info properties are correctly fetched. |
| 222 | + """ |
| 223 | + cloud = FakeRoborockCloud() |
| 224 | + |
| 225 | + fake_device1 = V1VacuumSimulator(duid="device_1") |
| 226 | + fake_device2 = V1VacuumSimulator( |
| 227 | + duid="device_2", |
| 228 | + network_info=replace(DEFAULT_NETWORK_INFO, ip="192.168.1.50", ssid="custom_wifi"), |
| 229 | + ) |
| 230 | + |
| 231 | + cloud.add_device(fake_device1) |
| 232 | + cloud.add_device(fake_device2) |
| 233 | + |
| 234 | + with cloud.patch_device_manager(): |
| 235 | + manager = await create_device_manager( |
| 236 | + user_params=UserParams(username="test_user", user_data=USER_DATA), |
| 237 | + cache=InMemoryCache(), |
| 238 | + ) |
| 239 | + devices = await manager.get_devices() |
| 240 | + |
| 241 | + assert len(devices) == 2 |
| 242 | + |
| 243 | + # Sort them by duid to ensure order |
| 244 | + devices.sort(key=lambda d: d.duid) |
| 245 | + |
| 246 | + device1 = devices[0] |
| 247 | + device2 = devices[1] |
| 248 | + |
| 249 | + assert device1.duid == "device_1" |
| 250 | + assert device2.duid == "device_2" |
| 251 | + |
| 252 | + # Refresh and verify network info on device1 (should have defaults) |
| 253 | + assert device1.v1_properties is not None |
| 254 | + assert device1.v1_properties.network_info is not None |
| 255 | + await device1.v1_properties.network_info.refresh() |
| 256 | + assert device1.v1_properties.network_info.ip == "1.1.1.1" |
| 257 | + assert device1.v1_properties.network_info.ssid == "test_wifi" |
| 258 | + |
| 259 | + # Refresh and verify network info on device2 (should have overridden values) |
| 260 | + assert device2.v1_properties is not None |
| 261 | + assert device2.v1_properties.network_info is not None |
| 262 | + await device2.v1_properties.network_info.refresh() |
| 263 | + assert device2.v1_properties.network_info.ip == "192.168.1.50" |
| 264 | + assert device2.v1_properties.network_info.ssid == "custom_wifi" |
0 commit comments