Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support devices with serialNumber as their property #124

Merged
merged 3 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion PyTado/interface/api/hops_tado.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
64 changes: 64 additions & 0 deletions tests/fixtures/tadox/rooms_and_devices.json
Original file line number Diff line number Diff line change
@@ -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": []
}
]
}
22 changes: 22 additions & 0 deletions tests/test_hops_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down Expand Up @@ -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")
wmalgadey marked this conversation as resolved.
Show resolved Hide resolved

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'
Loading