Skip to content

Commit

Permalink
fix: improve cloud token/keys retrival (#189)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Enhanced the handling of empty response cases in cloud key retrieval,
ensuring default keys are applied when necessary.
- Added logging to improve debugging of the cloud key retrieval process.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
chemelli74 and coderabbitai[bot] authored Jul 1, 2024
1 parent 6664fef commit feb855f
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion midealocal/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,22 @@ async def get_keys(self, appliance_id: int) -> dict[int, dict[str, Any]]:
endpoint="/v1/iot/secure/getToken",
data=data,
)
_LOGGER.debug(
"Response from get_keys() for appliance_id %s with method %s: %s",
appliance_id,
method,
response,
)
if response and "tokenlist" in response:
for token in response["tokenlist"]:
if token["udpId"] == udp_id:
result[method] = {
"token": token["token"].lower(),
"key": token["key"].lower(),
}
result.update(default_keys)
break
if not result:
result.update(default_keys)
return result

@staticmethod
Expand Down

0 comments on commit feb855f

Please sign in to comment.