-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Enhance token management in cloud command handling #56
Conversation
if self._iot_token_issued_at + self._session_by_authcode_response.data.refreshTokenExpire > (int(time.time())): | ||
self.check_or_refresh_session() | ||
else: | ||
raise Exception("Refresh token expired. Please re-login") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to create a token expired exception type so it can be caught
@@ -1,4 +1,5 @@ | |||
from dataclasses import dataclass | |||
from dataclasses import dataclass, field | |||
from datetime import time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import?
if int(response_body_dict.get("code")) != 200: | ||
raise Exception("Error check or refresh token: " + response_body_dict.get('msg', '')) | ||
|
||
identityId = response_body_dict.get('data', {}).get('identityId', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a dataclass for this, so you can do e.g IotToken().from_dict(response_body_dict.get('data', {}))
Or create one, plenty of examples in the make-em-mow branch
PR Review 🔍
|
PR Code Suggestions ✨
|
* start work on mowing * update mtrl nav * fix nav commands for none luba 1s * ruff format and so on * add product key to commands for checking device * fix blade on off * Try to implement MQTT response - Need helo on Lock * update protobufs with basestation * adding report info model and map conversions for lla enu * release 0.1.7 * try to keep last data if its missing in report cfg * fix report info * Add missing calls for ble sync as well as hook up callbacks, remove dead code and general clean up, added test call to verify things work * format and run ruff * add cloud as part of base MammotionDevice * rename http class * fix up the client sesion for http * update login to login_info * bump version to 0.2.1 * add start sync and sync maps calls to MammotionDevice * refactor mammotion to handle multiple devices and match to a name * update test examples * fix oops * fix quite a few errors and issues * stability improvements * fix more issues * adding movement commands * fix issue with device identification messing up sync maps * remove operation lock for mqtt * publish 0.2.7 * Add check and refresh token into send_cloud_command (#56) Co-authored-by: Andrea Cagnola <[email protected]> Co-authored-by: Michael Arthur <[email protected]> * add methods for getting credentials for storing in HA when reloading or restarting without having to re-login * fix queuing of requests for mqtt, sync maps now works bump version to 0.2.9 * don't create cloud or initiate cloud connection if there isn't credentials * bump version to 0.2.11 and catch small issue with futures queue being empty --------- Co-authored-by: Andrea Cagnola <[email protected]> Co-authored-by: d3dfantasy99 <[email protected]> Co-authored-by: Andrea Cagnola <[email protected]>
* start work on mowing * update mtrl nav * fix nav commands for none luba 1s * ruff format and so on * add product key to commands for checking device * fix blade on off * Try to implement MQTT response - Need helo on Lock * update protobufs with basestation * adding report info model and map conversions for lla enu * release 0.1.7 * try to keep last data if its missing in report cfg * fix report info * Add missing calls for ble sync as well as hook up callbacks, remove dead code and general clean up, added test call to verify things work * format and run ruff * add cloud as part of base MammotionDevice * rename http class * fix up the client sesion for http * update login to login_info * bump version to 0.2.1 * add start sync and sync maps calls to MammotionDevice * refactor mammotion to handle multiple devices and match to a name * update test examples * fix oops * fix quite a few errors and issues * stability improvements * fix more issues * adding movement commands * fix issue with device identification messing up sync maps * remove operation lock for mqtt * publish 0.2.7 * Add check and refresh token into send_cloud_command (#56) Co-authored-by: Andrea Cagnola <[email protected]> Co-authored-by: Michael Arthur <[email protected]> * add methods for getting credentials for storing in HA when reloading or restarting without having to re-login * fix queuing of requests for mqtt, sync maps now works bump version to 0.2.9 * don't create cloud or initiate cloud connection if there isn't credentials * bump version to 0.2.11 and catch small issue with futures queue being empty * fix issue with model having optional nickName --------- Co-authored-by: Andrea Cagnola <[email protected]> Co-authored-by: d3dfantasy99 <[email protected]> Co-authored-by: Andrea Cagnola <[email protected]>
Description
send_cloud_command
method to ensure token validity.Changes walkthrough 📝
cloud_gateway.py
Enhance token management in cloud command handling
pymammotion/aliyun/cloud_gateway.py
send_cloud_command
.check_or_refresh_session
method to handle tokenexpiration.
session_by_authcode_response.py
Update session response structure for token data
pymammotion/aliyun/dataclass/session_by_authcode_response.py
SessionByAuthCodeResponse
to include token data.field
import for future enhancements.