Skip to content

Commit

Permalink
small tweaks and a fix for bluetooth timeout throwing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
mikey0000 committed Sep 3, 2024
1 parent aeaa163 commit 425b60f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions pymammotion/aliyun/cloud_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
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
from alibabacloud_iot_api_gateway.models import CommonParams, Config, IoTApiRequest
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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion pymammotion/data/mqtt/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pymammotion/mammotion/devices/mammotion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 425b60f

Please sign in to comment.