From 425b60f4213ca69ce82d7fc40b6da29290702493 Mon Sep 17 00:00:00 2001 From: Michael Arthur Date: Wed, 4 Sep 2024 11:35:03 +1200 Subject: [PATCH] small tweaks and a fix for bluetooth timeout throwing an error --- pymammotion/aliyun/cloud_gateway.py | 9 ++++++--- pymammotion/data/mqtt/event.py | 2 +- pymammotion/mammotion/devices/mammotion.py | 2 +- pyproject.toml | 6 +++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pymammotion/aliyun/cloud_gateway.py b/pymammotion/aliyun/cloud_gateway.py index c4a04ab..837af8e 100644 --- a/pymammotion/aliyun/cloud_gateway.py +++ b/pymammotion/aliyun/cloud_gateway.py @@ -9,9 +9,7 @@ import string import time import uuid -from logging import getLogger, exception -from datetime import datetime -from urllib.parse import urlencode +from logging import getLogger from aiohttp import ClientSession from alibabacloud_iot_api_gateway.client import Client @@ -19,6 +17,7 @@ from alibabacloud_tea_util.client import Client as UtilClient from alibabacloud_tea_util.models import RuntimeOptions +from pymammotion.http.http import MammotionHTTP from pymammotion.aliyun.dataclass.aep_response import AepResponse from pymammotion.aliyun.dataclass.connect_response import ConnectResponse from pymammotion.aliyun.dataclass.dev_by_account_response import ( @@ -79,6 +78,7 @@ class CloudIOTGateway: def __init__(self, connect_response: ConnectResponse | None = None, login_by_oauth_response: LoginByOAuthResponse | None = None, aep_response: AepResponse | None = None, session_by_authcode_response: SessionByAuthCodeResponse | None = None, region_response: RegionResponse | None = None, dev_by_account: ListingDevByAccountResponse | None = None): """Initialize the CloudIOTGateway.""" + self.mammotion_http: MammotionHTTP | None = None self._app_key = APP_KEY self._app_secret = APP_SECRET self.domain = ALIYUN_DOMAIN @@ -616,3 +616,6 @@ def send_cloud_command(self, iot_id: str, command: bytes) -> str: @property def listing_dev_by_account_response(self): return self._devices_by_account_response + + def set_http(self, mammotion_http): + self.mammotion_http = mammotion_http diff --git a/pymammotion/data/mqtt/event.py b/pymammotion/data/mqtt/event.py index 9d13d07..e4f659f 100644 --- a/pymammotion/data/mqtt/event.py +++ b/pymammotion/data/mqtt/event.py @@ -148,7 +148,7 @@ def from_dicts(cls, payload: dict) -> "ThingEventMessage": elif identifier == "device_warning_event": params_obj = DeviceWarningEventParams(**params_dict) elif identifier == "device_config_req_event": - params_obj = payload.get("params", '') + params_obj = payload.get("params", {}) elif identifier == "device_notification_event": params_obj = DeviceNotificationEventParams(**params_dict) else: diff --git a/pymammotion/mammotion/devices/mammotion.py b/pymammotion/mammotion/devices/mammotion.py index 855e589..3b6ada1 100644 --- a/pymammotion/mammotion/devices/mammotion.py +++ b/pymammotion/mammotion/devices/mammotion.py @@ -266,6 +266,7 @@ async def login(account: str, password: str) -> CloudIOTGateway: _LOGGER.debug("CountryCode: " + country_code) _LOGGER.debug("AuthCode: " + mammotion_http.login_info.authorization_code) loop = asyncio.get_running_loop() + cloud_client.set_http(mammotion_http) await loop.run_in_executor(None, cloud_client.get_region, country_code, mammotion_http.login_info.authorization_code) await cloud_client.connect() await cloud_client.login_by_oauth(country_code, mammotion_http.login_info.authorization_code) @@ -815,7 +816,6 @@ async def _execute_command_locked(self, key: str, command: bytes) -> bytes: except asyncio.TimeoutError: timeout_expired = True notify_msg = b'' - self._notify_future.set_result(notify_msg) finally: if not timeout_expired: timeout_handle.cancel() diff --git a/pyproject.toml b/pyproject.toml index 9eeb437..2f11733 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "pymammotion" -version = "0.2.25" +version = "0.2.26" [tool.poetry] name = "pymammotion" -version = "0.2.25" +version = "0.2.26" license = "GNU-3.0" description = "" readme = "README.md" @@ -53,7 +53,7 @@ mypy = "^1.10.0" pre-commit = "^3.8.0" [tool.bumpver] -current_version = "0.2.25" +current_version = "0.2.26" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true