diff --git a/PyTado/interface/api/hops_tado.py b/PyTado/interface/api/hops_tado.py index 7251369..74fed39 100644 --- a/PyTado/interface/api/hops_tado.py +++ b/PyTado/interface/api/hops_tado.py @@ -72,9 +72,13 @@ def get_devices(self): devices = [device for room in rooms for device in room["devices"]] for device in devices: + serial_number = device.get("serialNo", device.get("serialNumber")) + if not serial_number: + continue + request = TadoXRequest() request.domain = Domain.DEVICES - request.device = device["serialNo"] + request.device = serial_number device.update(self._http.request(request)) if "otherDevices" in rooms_and_devices: diff --git a/tests/fixtures/tadox/rooms_and_devices.json b/tests/fixtures/tadox/rooms_and_devices.json new file mode 100644 index 0000000..077944c --- /dev/null +++ b/tests/fixtures/tadox/rooms_and_devices.json @@ -0,0 +1,64 @@ +{ + "otherDevices": [ + { + "connection": { + "state": "CONNECTED" + }, + "firmwareVersion": "245.1", + "serialNumber": "IB1234567890", + "type": "IB02" + } + ], + "rooms": [ + { + "deviceManualControlTermination": { + "durationInSeconds": null, + "type": "MANUAL" + }, + "devices": [ + { + "batteryState": "NORMAL", + "childLockEnabled": false, + "connection": { + "state": "CONNECTED" + }, + "firmwareVersion": "243.1", + "mountingState": "CALIBRATED", + "serialNumber": "VA1234567890", + "temperatureAsMeasured": 17.00, + "temperatureOffset": 0.0, + "type": "VA04" + } + ], + "roomId": 1, + "roomName": "Room 1", + "zoneControllerAssignable": false, + "zoneControllers": [] + }, + { + "deviceManualControlTermination": { + "durationInSeconds": null, + "type": "MANUAL" + }, + "devices": [ + { + "batteryState": "NORMAL", + "childLockEnabled": false, + "connection": { + "state": "CONNECTED" + }, + "firmwareVersion": "243.1", + "mountingState": "CALIBRATED", + "serialNumber": "VA1234567891", + "temperatureAsMeasured": 18.00, + "temperatureOffset": 0.0, + "type": "VA04" + } + ], + "roomId": 2, + "roomName": " Room 2", + "zoneControllerAssignable": false, + "zoneControllers": [] + } + ] + } diff --git a/tests/test_hops_zone.py b/tests/test_hops_zone.py index 8b7fbb8..acfb0f9 100644 --- a/tests/test_hops_zone.py +++ b/tests/test_hops_zone.py @@ -44,6 +44,17 @@ def check_get_state(zone_id): get_state_patch.start() self.addCleanup(get_state_patch.stop) + def set_get_devices_fixture(self, filename: str) -> None: + def get_devices(): + return json.loads(common.load_fixture(filename)) + + get_devices_patch = mock.patch( + "PyTado.interface.api.TadoX.get_devices", + side_effect=get_devices, + ) + get_devices_patch.start() + self.addCleanup(get_devices_patch.stop) + def test_tadox_heating_auto_mode(self): """Test general homes response.""" @@ -145,3 +156,14 @@ def test_tadox_heating_manual_off(self): assert mode.tado_mode is None assert mode.target_temp is None assert mode.zone_id == 1 + + def test_get_devices(self): + """ Test get_devices method """ + self.set_get_devices_fixture("tadox/rooms_and_devices.json") + + devices_and_rooms = self.tado_client.get_devices() + rooms = devices_and_rooms['rooms'] + assert len(rooms) == 2 + room_1 = rooms[0] + assert room_1['roomName'] == 'Room 1' + assert room_1['devices'][0]['serialNumber'] == 'VA1234567890'