Skip to content

Commit 07c353e

Browse files
committed
Improve debug command and API tests
1 parent cf437b4 commit 07c353e

File tree

5 files changed

+55
-19
lines changed

5 files changed

+55
-19
lines changed

.github/workflows/automated-api-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ jobs:
2626
touch .env
2727
echo "USERNAME=${{ secrets.THERMIA_USERNAME }}" >> .env
2828
echo "PASSWORD=${{ secrets.THERMIA_PASSWORD }}" >> .env
29-
- name: Create a debug log file
29+
- name: Run tests against Thermia API
3030
run: |
3131
python scripts/test_api.py

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ __pycache__/
99
MANIFEST
1010
build/
1111
dist/
12+
.eggs/
13+
ThermiaOnlineAPI.egg-info/
1214

1315
# Debug file
1416
debug.txt

ThermiaOnlineAPI/model/HeatPump.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,8 @@ def debug(self) -> str:
948948
debug_str += pretty_json_string_except(
949949
self.__info,
950950
[
951+
"deviceId",
952+
"name",
951953
"address",
952954
"macAddress",
953955
"ownerId",
@@ -967,7 +969,17 @@ def debug(self) -> str:
967969

968970
debug_str += pretty_json_string_except(
969971
self.__device_data,
970-
["macAddress", "owner", "retailerAccess", "retailerId", "id", "status"],
972+
[
973+
"deviceId",
974+
"location",
975+
"name",
976+
"macAddress",
977+
"owner",
978+
"retailerAccess",
979+
"retailerId",
980+
"id",
981+
"status",
982+
],
971983
)
972984

973985
installation_profile_id = get_dict_value_or_none(

ThermiaOnlineAPI/tests/debug_files/diplomat_duo_921.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22
self.__info:
33
{
44
"createdWhen": "2020-01-02T13:00:44.257",
5-
"deviceId": 1234567,
5+
"deviceConnectionType": "Dcm",
66
"hasLinkUnit": false,
77
"installationProfileId": 1001,
88
"isOnline": true,
99
"lastOnline": "2024-10-13T16:44:16.407",
1010
"model": "",
11-
"name": "Thermia",
1211
"operationManualUrl": "https://thermia.com/products/thermia-online/",
13-
"serialNumber": null
12+
"owner": null,
13+
"profile": {
14+
"icon": 1,
15+
"id": 1001,
16+
"name": "DHP H/L/C 921",
17+
"thermiaName": "Diplomat / Diplomat Duo"
18+
},
19+
"serialNumber": null,
20+
"status": {
21+
"activeAlarms": 0,
22+
"activeCriticalAlarms": 0,
23+
"unreadErrors": 0,
24+
"unreadInfo": 20,
25+
"unreadWarnings": 20
26+
}
1427
}
1528

1629

@@ -47,11 +60,11 @@ self.__status:
4760

4861
self.__device_data:
4962
{
50-
"deviceId": 1234567,
63+
"deviceConnectionType": "Dcm",
64+
"firmwareVersion": "1.42",
5165
"isOnline": true,
5266
"lastOnline": "2024-10-13T13:44:16.407",
53-
"location": null,
54-
"name": "Thermia",
67+
"model": "",
5568
"profile": {
5669
"icon": 1,
5770
"id": 1001,

scripts/test_api.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,30 @@
2020
"programVersion",
2121
"reducedHeatingEffect",
2222
# self.__device_data related
23-
"firmwareVersion",
2423
"lastOnline",
24+
]
25+
26+
REPEATING_TEST_EXCLUDED_LINE_STRINGS = [
2527
# Register group related
2628
"registerValue",
2729
"timeStamp",
2830
"value",
2931
]
3032

3133

32-
def test_excluded_string_in_line(line: str) -> bool:
33-
for excluded_string in TEST_EXCLUDED_LINE_STRINGS:
34-
if excluded_string in line:
34+
def test_excluded_string_in_lines(line1: str, line2) -> bool:
35+
if (
36+
len(TEST_EXCLUDED_LINE_STRINGS) != 0
37+
and TEST_EXCLUDED_LINE_STRINGS[0] in line1
38+
and TEST_EXCLUDED_LINE_STRINGS[0] in line2
39+
):
40+
del TEST_EXCLUDED_LINE_STRINGS[0]
41+
return True
42+
43+
for excluded_string in REPEATING_TEST_EXCLUDED_LINE_STRINGS:
44+
if excluded_string in line1 and excluded_string in line2:
3545
return True
46+
3647
return False
3748

3849

@@ -67,19 +78,17 @@ def test_excluded_string_in_line(line: str) -> bool:
6778
f"{absolute_path}/../ThermiaOnlineAPI/tests/debug_files/diplomat_duo_921.txt"
6879
)
6980

70-
with open("debug.txt", "r") as f:
81+
with open(existing_data_filename, "r") as f:
7182
existing_debug_data = f.read()
7283

73-
for [existing_line, new_line] in zip(
74-
existing_debug_data.split("\n"), debug_data.split("\n")
84+
for [idx, [existing_line, new_line]] in enumerate(
85+
zip(existing_debug_data.split("\n"), debug_data.split("\n"))
7586
):
76-
if test_excluded_string_in_line(existing_line) and test_excluded_string_in_line(
77-
new_line
78-
):
87+
if test_excluded_string_in_lines(existing_line, new_line):
7988
continue
8089

8190
if existing_line != new_line:
82-
print("Existing data does not match new data")
91+
print("Existing data does not match new data on line " + str(idx + 1))
8392
print("Existing line: " + existing_line)
8493
print("New line: " + new_line)
8594
print("\n")

0 commit comments

Comments
 (0)