pymammotion 0.4.52__py3-none-any.whl → 0.4.54__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ from alibabacloud_iot_api_gateway.models import CommonParams, Config, IoTApiRequ
16
16
  from alibabacloud_tea_util.client import Client as UtilClient
17
17
  from alibabacloud_tea_util.models import RuntimeOptions
18
18
  from Tea.exceptions import UnretryableException
19
+ from orjson.orjson import JSONDecodeError
19
20
 
20
21
  from pymammotion.aliyun.client import Client
21
22
  from pymammotion.aliyun.model.aep_response import AepResponse
@@ -138,6 +139,14 @@ class CloudIOTGateway:
138
139
  hashed_uuid = hashlib.sha1(f"{uuid.getnode()}".encode()).hexdigest()
139
140
  return "".join(itertools.islice(itertools.cycle(hashed_uuid), length))
140
141
 
142
+ @staticmethod
143
+ def parse_json_response(response_body_str: str) -> dict:
144
+ try:
145
+ return json.loads(response_body_str) if response_body_str is not None else {}
146
+ except JSONDecodeError:
147
+ logger.error("Couldn't decode message %s", response_body_str)
148
+ return {}
149
+
141
150
  def sign(self, data):
142
151
  """Generate signature for the given data."""
143
152
  keys = ["appKey", "clientId", "deviceSn", "timestamp"]
@@ -207,7 +216,7 @@ class CloudIOTGateway:
207
216
  response_body_str = response.body.decode("utf-8")
208
217
 
209
218
  # Load the JSON string into a dictionary
210
- response_body_dict = json.loads(response_body_str)
219
+ response_body_dict = self.parse_json_response(response_body_str)
211
220
 
212
221
  if int(response_body_dict.get("code")) != 200:
213
222
  raise Exception("Error in getting regions: " + response_body_dict["msg"])
@@ -264,7 +273,7 @@ class CloudIOTGateway:
264
273
 
265
274
  response_body_str = response.body.decode("utf-8")
266
275
 
267
- response_body_dict = json.loads(response_body_str)
276
+ response_body_dict = self.parse_json_response(response_body_str)
268
277
 
269
278
  if int(response_body_dict.get("code")) != 200:
270
279
  raise Exception("Error in getting mqtt credentials: " + response_body_dict["msg"])
@@ -464,7 +473,7 @@ class CloudIOTGateway:
464
473
  response_body_str = response.body.decode("utf-8")
465
474
 
466
475
  # Load the JSON string into a dictionary
467
- response_body_dict = json.loads(response_body_str)
476
+ response_body_dict = self.parse_json_response(response_body_str)
468
477
 
469
478
  session_by_auth = SessionByAuthCodeResponse.from_dict(response_body_dict)
470
479
 
@@ -479,7 +488,7 @@ class CloudIOTGateway:
479
488
 
480
489
  return response.body
481
490
 
482
- async def sign_out(self) -> None:
491
+ async def sign_out(self) -> dict:
483
492
  config = Config(
484
493
  app_key=self._app_key,
485
494
  app_secret=self._app_secret,
@@ -520,8 +529,7 @@ class CloudIOTGateway:
520
529
  response_body_str = response.body.decode("utf-8")
521
530
 
522
531
  # Load the JSON string into a dictionary
523
- response_body_dict = json.loads(response_body_str)
524
- logger.debug(response_body_dict)
532
+ response_body_dict = self.parse_json_response(response_body_str)
525
533
  return response_body_dict
526
534
 
527
535
  async def check_or_refresh_session(self):
@@ -567,7 +575,7 @@ class CloudIOTGateway:
567
575
  response_body_str = response.body.decode("utf-8")
568
576
 
569
577
  # Load the JSON string into a dictionary
570
- response_body_dict = json.loads(response_body_str)
578
+ response_body_dict = self.parse_json_response(response_body_str)
571
579
 
572
580
  if int(response_body_dict.get("code")) != 200:
573
581
  logger.error(response_body_dict)
@@ -625,7 +633,7 @@ class CloudIOTGateway:
625
633
  response_body_str = response.body.decode("utf-8")
626
634
 
627
635
  # Load the JSON string into a dictionary
628
- response_body_dict = json.loads(response_body_str)
636
+ response_body_dict = self.parse_json_response(response_body_str)
629
637
 
630
638
  if int(response_body_dict.get("code")) != 200:
631
639
  raise Exception("Error in creating session: " + response_body_dict["msg"])
@@ -666,7 +674,7 @@ class CloudIOTGateway:
666
674
  response_body_str = response.body.decode("utf-8")
667
675
 
668
676
  # Load the JSON string into a dictionary
669
- response_body_dict = json.loads(response_body_str)
677
+ response_body_dict = self.parse_json_response(response_body_str)
670
678
 
671
679
  if int(response_body_dict.get("code")) != 200:
672
680
  raise Exception("Error in creating session: " + response_body_dict["msg"])
@@ -731,8 +739,9 @@ class CloudIOTGateway:
731
739
  logger.debug(response.body)
732
740
  logger.debug(iot_id)
733
741
 
742
+
734
743
  response_body_str = response.body.decode("utf-8")
735
- response_body_dict = json.loads(response_body_str) if response_body_str is not None else {}
744
+ response_body_dict = self.parse_json_response(response_body_str)
736
745
 
737
746
  if int(response_body_dict.get("code")) != 200:
738
747
  logger.error(
@@ -133,7 +133,7 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
133
133
  """Stop all tasks and disconnect."""
134
134
  if self._ble_sync_task:
135
135
  self._ble_sync_task.cancel()
136
- if self._client is not None:
136
+ if self._client is not None and self._client.is_connected:
137
137
  await self._client.disconnect()
138
138
 
139
139
  async def queue_command(self, key: str, **kwargs: Any) -> bytes | None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pymammotion
3
- Version: 0.4.52
3
+ Version: 0.4.54
4
4
  Summary:
5
5
  License: GPL-3.0
6
6
  Author: Michael Arthur
@@ -1,7 +1,7 @@
1
1
  pymammotion/__init__.py,sha256=H-U94bNLp0LPC6hkRopVEUlUsZSR97n7WfKGPjK1GMg,1638
2
2
  pymammotion/aliyun/__init__.py,sha256=T1lkX7TRYiL4nqYanG4l4MImV-SlavSbuooC-W-uUGw,29
3
3
  pymammotion/aliyun/client.py,sha256=44YqBt0advxbYYXs25Jpq438lhEXrP6xaBWWMGBLdp4,9603
4
- pymammotion/aliyun/cloud_gateway.py,sha256=_qwntXZjj2VzX5x_9LSeq-lW0CRsBYdGO0Wn8e5kIHk,28328
4
+ pymammotion/aliyun/cloud_gateway.py,sha256=DAawjvmlrdYrxzA-C4aXPN0hTx9FIXoIn5I4JSn2adw,28712
5
5
  pymammotion/aliyun/model/aep_response.py,sha256=EY4uMTJ4F9rvbcXnAOc5YKi7q__9kIVgfDwfyr65Gk0,421
6
6
  pymammotion/aliyun/model/connect_response.py,sha256=Yz-fEbDzgGPTo5Of2oAjmFkSv08T7ze80pQU4k-gKIU,824
7
7
  pymammotion/aliyun/model/dev_by_account_response.py,sha256=P9yYy4Z2tLkJSqXA_5XGaCUliSSVa5ILl7VoMtL_tCA,977
@@ -72,7 +72,7 @@ pymammotion/mammotion/control/joystick.py,sha256=QfBVxM_gxpWsZAGO90whtgxCI2tIZ3T
72
72
  pymammotion/mammotion/devices/__init__.py,sha256=f2qQFPgLGmV85W2hSlMUh5BYuht9o_Ar_JEAAMD4fsE,102
73
73
  pymammotion/mammotion/devices/base.py,sha256=qDh7P7fnakDKgxTqjNLcQg8eE-6gHJaXAV0ONjhy_IU,12038
74
74
  pymammotion/mammotion/devices/mammotion.py,sha256=SBisZ7zbLQmo8WpLQze5lI2gDawZpzLWZ9ANTkiLV8s,14451
75
- pymammotion/mammotion/devices/mammotion_bluetooth.py,sha256=sgfL4sz6WkIlr2bvYplzxsudmzATNE-z3UGe0K1Csng,18919
75
+ pymammotion/mammotion/devices/mammotion_bluetooth.py,sha256=MWoaiHqNRh_bHlvjmVPRjYVauVNIVgDpOIsC-UDvYMc,18949
76
76
  pymammotion/mammotion/devices/mammotion_cloud.py,sha256=P352E-pcbG6wA-RXubI51EUJ3UUQcqJkxRDIqh3g-58,14217
77
77
  pymammotion/mqtt/__init__.py,sha256=Ocs5e-HLJvTuDpVXyECEsWIvwsUaxzj7lZ9mSYutNDY,105
78
78
  pymammotion/mqtt/linkkit/__init__.py,sha256=ENgc3ynd2kd9gMQR3-kgmCu6Ed9Y6XCIzU0zFReUlkk,80
@@ -123,7 +123,7 @@ pymammotion/utility/movement.py,sha256=N75oAoAgFydqoaOedYIxGUHmuTCtPzAOtb-d_29tp
123
123
  pymammotion/utility/mur_mur_hash.py,sha256=xEfOZVbqRawJj66eLgtnZ85OauDR47oIPr29OHelzPI,4468
124
124
  pymammotion/utility/periodic.py,sha256=MbeSb9cfhxzYmdT_RiE0dZe3H9IfbQW_zSqhmSX2RUc,3321
125
125
  pymammotion/utility/rocker_util.py,sha256=6tX7sS87qoQC_tsxbx3NLL-HgS08wtzXiZkhDiz7uo0,7179
126
- pymammotion-0.4.52.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
127
- pymammotion-0.4.52.dist-info/METADATA,sha256=x_e3b_Q7aNFN5jnivYyy49BKm52a0Zm7WrqK3u8SExc,3878
128
- pymammotion-0.4.52.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
129
- pymammotion-0.4.52.dist-info/RECORD,,
126
+ pymammotion-0.4.54.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
127
+ pymammotion-0.4.54.dist-info/METADATA,sha256=jSP_SsEcwPL1U4Bl7JpJehngXz1LG6JRwon8scc3d8s,3878
128
+ pymammotion-0.4.54.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
129
+ pymammotion-0.4.54.dist-info/RECORD,,