Skip to content

Commit

Permalink
Improve debug command and API tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Nov 29, 2024
1 parent cf437b4 commit 07c353e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automated-api-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
touch .env
echo "USERNAME=${{ secrets.THERMIA_USERNAME }}" >> .env
echo "PASSWORD=${{ secrets.THERMIA_PASSWORD }}" >> .env
- name: Create a debug log file
- name: Run tests against Thermia API
run: |
python scripts/test_api.py
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ __pycache__/
MANIFEST
build/
dist/
.eggs/
ThermiaOnlineAPI.egg-info/

# Debug file
debug.txt
Expand Down
14 changes: 13 additions & 1 deletion ThermiaOnlineAPI/model/HeatPump.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,8 @@ def debug(self) -> str:
debug_str += pretty_json_string_except(
self.__info,
[
"deviceId",
"name",
"address",
"macAddress",
"ownerId",
Expand All @@ -967,7 +969,17 @@ def debug(self) -> str:

debug_str += pretty_json_string_except(
self.__device_data,
["macAddress", "owner", "retailerAccess", "retailerId", "id", "status"],
[
"deviceId",
"location",
"name",
"macAddress",
"owner",
"retailerAccess",
"retailerId",
"id",
"status",
],
)

installation_profile_id = get_dict_value_or_none(
Expand Down
25 changes: 19 additions & 6 deletions ThermiaOnlineAPI/tests/debug_files/diplomat_duo_921.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
self.__info:
{
"createdWhen": "2020-01-02T13:00:44.257",
"deviceId": 1234567,
"deviceConnectionType": "Dcm",
"hasLinkUnit": false,
"installationProfileId": 1001,
"isOnline": true,
"lastOnline": "2024-10-13T16:44:16.407",
"model": "",
"name": "Thermia",
"operationManualUrl": "https://thermia.com/products/thermia-online/",
"serialNumber": null
"owner": null,
"profile": {
"icon": 1,
"id": 1001,
"name": "DHP H/L/C 921",
"thermiaName": "Diplomat / Diplomat Duo"
},
"serialNumber": null,
"status": {
"activeAlarms": 0,
"activeCriticalAlarms": 0,
"unreadErrors": 0,
"unreadInfo": 20,
"unreadWarnings": 20
}
}


Expand Down Expand Up @@ -47,11 +60,11 @@ self.__status:

self.__device_data:
{
"deviceId": 1234567,
"deviceConnectionType": "Dcm",
"firmwareVersion": "1.42",
"isOnline": true,
"lastOnline": "2024-10-13T13:44:16.407",
"location": null,
"name": "Thermia",
"model": "",
"profile": {
"icon": 1,
"id": 1001,
Expand Down
31 changes: 20 additions & 11 deletions scripts/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,30 @@
"programVersion",
"reducedHeatingEffect",
# self.__device_data related
"firmwareVersion",
"lastOnline",
]

REPEATING_TEST_EXCLUDED_LINE_STRINGS = [
# Register group related
"registerValue",
"timeStamp",
"value",
]


def test_excluded_string_in_line(line: str) -> bool:
for excluded_string in TEST_EXCLUDED_LINE_STRINGS:
if excluded_string in line:
def test_excluded_string_in_lines(line1: str, line2) -> bool:
if (
len(TEST_EXCLUDED_LINE_STRINGS) != 0
and TEST_EXCLUDED_LINE_STRINGS[0] in line1
and TEST_EXCLUDED_LINE_STRINGS[0] in line2
):
del TEST_EXCLUDED_LINE_STRINGS[0]
return True

for excluded_string in REPEATING_TEST_EXCLUDED_LINE_STRINGS:
if excluded_string in line1 and excluded_string in line2:
return True

return False


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

with open("debug.txt", "r") as f:
with open(existing_data_filename, "r") as f:
existing_debug_data = f.read()

for [existing_line, new_line] in zip(
existing_debug_data.split("\n"), debug_data.split("\n")
for [idx, [existing_line, new_line]] in enumerate(
zip(existing_debug_data.split("\n"), debug_data.split("\n"))
):
if test_excluded_string_in_line(existing_line) and test_excluded_string_in_line(
new_line
):
if test_excluded_string_in_lines(existing_line, new_line):
continue

if existing_line != new_line:
print("Existing data does not match new data")
print("Existing data does not match new data on line " + str(idx + 1))
print("Existing line: " + existing_line)
print("New line: " + new_line)
print("\n")
Expand Down

0 comments on commit 07c353e

Please sign in to comment.