Skip to content

Commit 7b0de93

Browse files
committed
Fix issue with returning invisible operation modes
1 parent 3b5ff47 commit 7b0de93

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

ThermiaOnlineAPI/api/ThermiaAPI.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,18 @@ def get_group_operational_operation(self, device: ThermiaHeatPump):
286286

287287
if operation_modes_data is not None:
288288
operation_modes_map = map(
289-
lambda values: {
290-
values.get("value"): values.get("name").split(
291-
"REG_VALUE_OPERATION_MODE_"
292-
)[1],
293-
},
289+
lambda values: (
290+
{
291+
values.get("value"): values.get("name").split(
292+
"REG_VALUE_OPERATION_MODE_"
293+
)[1],
294+
}
295+
if values.get("visible")
296+
else {}
297+
),
294298
operation_modes_data,
295299
)
296-
operation_modes_list = list(operation_modes_map)
300+
operation_modes_list = list(filter(lambda x: x != {}, operation_modes_map))
297301
operation_modes = ChainMap(*operation_modes_list)
298302

299303
current_operation_mode = [
@@ -677,7 +681,9 @@ def __authenticate(self) -> bool:
677681
"client_id": THERMIA_AZURE_AUTH_CLIENT_ID_AND_SCOPE,
678682
"redirect_uri": THERMIA_AZURE_AUTH_REDIRECT_URI,
679683
"scope": THERMIA_AZURE_AUTH_CLIENT_ID_AND_SCOPE,
680-
"code": request_confirmed.url.split("code=")[1],
684+
"code": utils.get_list_value_or_default(
685+
request_confirmed.url.split("code="), 1, ""
686+
),
681687
"code_verifier": code_challenge,
682688
"grant_type": "authorization_code",
683689
}

ThermiaOnlineAPI/utils/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ def get_dict_value_or_default(dictionary, key, default: T) -> T:
2323
return dictionary[key]
2424

2525

26+
def get_list_value_or_default(list, idx, default: T) -> T:
27+
try:
28+
return list[idx]
29+
except IndexError:
30+
return default
31+
32+
2633
def pretty_print(json_object):
2734
print(json.dumps(json_object, indent=4, sort_keys=True))
2835
print("\n")

0 commit comments

Comments
 (0)