pymammotion 0.2.12__py3-none-any.whl → 0.2.14__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.

Potentially problematic release.


This version of pymammotion might be problematic. Click here for more details.

@@ -52,6 +52,9 @@ class SetupException(Exception):
52
52
  class AuthRefreshException(Exception):
53
53
  """Raise exception when library cannot refresh token."""
54
54
 
55
+ class DeviceOfflineException(Exception):
56
+ """Raise exception when device is offline."""
57
+
55
58
 
56
59
  class CloudIOTGateway:
57
60
  """Class for interacting with Aliyun Cloud IoT Gateway."""
@@ -416,10 +419,15 @@ class CloudIOTGateway:
416
419
  # Load the JSON string into a dictionary
417
420
  response_body_dict = json.loads(response_body_str)
418
421
 
419
- if int(response_body_dict.get("code")) != 200:
420
- raise Exception("Error in creating session: " + response_body_dict["msg"])
422
+ session_by_auth = SessionByAuthCodeResponse.from_dict(response_body_dict)
421
423
 
422
- self._session_by_authcode_response = SessionByAuthCodeResponse.from_dict(response_body_dict)
424
+ if int(session_by_auth.code) != 200:
425
+ raise Exception("Error in creating session: " + response_body_str)
426
+
427
+ if session_by_auth.data.identityId is None:
428
+ raise Exception("Error in creating session: " + response_body_str)
429
+
430
+ self._session_by_authcode_response = session_by_auth
423
431
  self._iot_token_issued_at = int(time.time())
424
432
 
425
433
  return response.body
@@ -472,17 +480,13 @@ class CloudIOTGateway:
472
480
  if int(response_body_dict.get("code")) != 200:
473
481
  raise Exception("Error check or refresh token: " + response_body_dict.get('msg', ''))
474
482
 
475
- identityId = response_body_dict.get('data', {}).get('identityId', None)
476
- refreshTokenExpire = response_body_dict.get('data', {}).get('refreshTokenExpire', None)
477
- iotToken = response_body_dict.get('data', {}).get('iotToken', None)
478
- iotTokenExpire = response_body_dict.get('data', {}).get('iotTokenExpire', None)
479
- refreshToken = response_body_dict.get('data', {}).get('refreshToken', None)
480
-
483
+ session = SessionByAuthCodeResponse.from_dict(response_body_dict)
484
+ session_data = session.data
481
485
 
482
- if (identityId is None or refreshTokenExpire is None or iotToken is None or iotTokenExpire is None or refreshToken is None):
486
+ if session_data.identityId is None or session_data.refreshTokenExpire is None or session_data.iotToken is None or session_data.iotTokenExpire is None or session_data.refreshToken is None:
483
487
  raise Exception("Error check or refresh token: Parameters not correct")
484
488
 
485
- self._session_by_authcode_response = SessionByAuthCodeResponse.from_dict(response_body_dict)
489
+ self._session_by_authcode_response = session
486
490
  self._iot_token_issued_at = int(time.time())
487
491
 
488
492
 
@@ -591,6 +595,7 @@ class CloudIOTGateway:
591
595
  if response_body_dict.get("code") == 29003:
592
596
  raise SetupException(response_body_dict.get("code"))
593
597
  if response_body_dict.get("code") == 6205:
598
+ raise DeviceOfflineException(response_body_dict.get("code"))
594
599
  """Device is offline."""
595
600
 
596
601
  return message_id
@@ -95,9 +95,9 @@ class DeviceWarningEventParams(GeneralParams):
95
95
 
96
96
  @dataclass
97
97
  class ThingEventMessage(DataClassORJSONMixin):
98
- method: Literal["thing.events"]
98
+ method: Literal["thing.events", "thing.properties"]
99
99
  id: str
100
- params: Union[DeviceProtobufMsgEventParams, DeviceWarningEventParams]
100
+ params: Union[DeviceProtobufMsgEventParams, DeviceWarningEventParams, str]
101
101
  version: Literal["1.0"]
102
102
 
103
103
  @classmethod
@@ -114,6 +114,8 @@ class ThingEventMessage(DataClassORJSONMixin):
114
114
  params_obj = DeviceProtobufMsgEventParams(**params_dict)
115
115
  elif identifier == "device_warning_event":
116
116
  params_obj = DeviceWarningEventParams(**params_dict)
117
+ elif identifier == "device_config_req_event":
118
+ params_obj = payload.get("params", '')
117
119
  else:
118
120
  raise ValueError(f"Unknown identifier: {identifier}")
119
121
 
@@ -29,7 +29,7 @@ from bleak_retry_connector import (
29
29
  establish_connection,
30
30
  )
31
31
 
32
- from pymammotion.aliyun.cloud_gateway import CloudIOTGateway
32
+ from pymammotion.aliyun.cloud_gateway import CloudIOTGateway, DeviceOfflineException, SetupException
33
33
  from pymammotion.aliyun.dataclass.dev_by_account_response import Device
34
34
  from pymammotion.bluetooth import BleMessage
35
35
  from pymammotion.const import MAMMOTION_DOMAIN
@@ -1070,9 +1070,23 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
1070
1070
  """Send command to device and read response."""
1071
1071
  try:
1072
1072
  return await self._execute_command_locked(key, command)
1073
+ except DeviceOfflineException as ex:
1074
+ _LOGGER.debug(
1075
+ "%s: device offline in _send_command_locked: %s",
1076
+ self.device.nickName,
1077
+ ex,
1078
+ )
1079
+ except SetupException as ex:
1080
+ session = self._mqtt_client.get_cloud_client().get_session_by_authcode_response()
1081
+ _LOGGER.debug(
1082
+ "%s: session identityId mssing in _send_command_locked: %s",
1083
+ self.device.nickName,
1084
+ session,
1085
+ )
1086
+ if session.data.identityId is None:
1087
+ await self._mqtt_client.get_cloud_client().session_by_auth_code()
1088
+
1073
1089
  except Exception as ex:
1074
- # Disconnect so we can reset state and try again
1075
- await asyncio.sleep(DBUS_ERROR_BACKOFF_TIME)
1076
1090
  _LOGGER.debug(
1077
1091
  "%s: error in _send_command_locked: %s",
1078
1092
  self.device.nickName,
@@ -1085,6 +1099,7 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
1085
1099
  assert self._mqtt_client is not None
1086
1100
  self._key = key
1087
1101
  _LOGGER.debug("%s: Sending command: %s", self.device.nickName, key)
1102
+
1088
1103
  await self.loop.run_in_executor(None, self._mqtt_client.get_cloud_client().send_cloud_command, self.iot_id, command)
1089
1104
  future = MammotionFuture()
1090
1105
  self._waiting_queue.append(future)
@@ -1132,7 +1147,10 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
1132
1147
  _LOGGER.debug("Thing event received")
1133
1148
  event = ThingEventMessage.from_dicts(payload)
1134
1149
  params = event.params
1135
- if params.identifier == "device_protobuf_msg_event":
1150
+ if isinstance(params, str):
1151
+ _LOGGER.debug("config event %s", str)
1152
+ return
1153
+ if params.identifier == "device_protobuf_msg_event" and params.thingType == "thing.events":
1136
1154
  _LOGGER.debug("Protobuf event")
1137
1155
  binary_data = base64.b64decode(params.value.get("content", ""))
1138
1156
  self._update_raw_data(cast(bytes, binary_data))
@@ -1153,6 +1171,8 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
1153
1171
  if not fut.fut.cancelled():
1154
1172
  fut.resolve(cast(bytes, binary_data))
1155
1173
  await self._state_manager.notification(new_msg)
1174
+ if params.thingType == "thing.properties":
1175
+ _LOGGER.debug(event)
1156
1176
 
1157
1177
  async def _handle_mqtt_message(self, topic: str, payload: dict) -> None:
1158
1178
  """Async handler for incoming MQTT messages."""
@@ -1163,3 +1183,4 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
1163
1183
  self._mqtt_client.disconnect()
1164
1184
 
1165
1185
 
1186
+
@@ -70,7 +70,7 @@ class MammotionMQTT:
70
70
  username=self._mqtt_username,
71
71
  )
72
72
 
73
- self._linkkit_client.enable_logger(level=logging.DEBUG)
73
+ self._linkkit_client.enable_logger(level=logging.ERROR)
74
74
  self._linkkit_client.on_connect = self._thing_on_connect
75
75
  self._linkkit_client.on_disconnect = self._on_disconnect
76
76
  self._linkkit_client.on_thing_enable = self._thing_on_thing_enable
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymammotion
3
- Version: 0.2.12
3
+ Version: 0.2.14
4
4
  Summary:
5
5
  License: GNU-3.0
6
6
  Author: Michael Arthur
@@ -1,6 +1,6 @@
1
1
  pymammotion/__init__.py,sha256=kmnjdt3AEMejIz5JK7h1tTJj5ZriAgKwZBa3ScA4-Ao,1516
2
2
  pymammotion/aliyun/__init__.py,sha256=T1lkX7TRYiL4nqYanG4l4MImV-SlavSbuooC-W-uUGw,29
3
- pymammotion/aliyun/cloud_gateway.py,sha256=IqmxgjDIgRoZvJvQnwYGOSl4XaCV4MoMKTlfhC9-6Ys,21830
3
+ pymammotion/aliyun/cloud_gateway.py,sha256=FCQzc24PHAhdO0rovTNv1yax4fG60CsLK24CxJikP5Y,21856
4
4
  pymammotion/aliyun/cloud_service.py,sha256=YWcKuKK6iRWy5mTnBYgHxcCusiRGGzQt3spSf7dGDss,2183
5
5
  pymammotion/aliyun/dataclass/aep_response.py,sha256=8f6GIP58ve8gd6AL3HBoXxsy0n2q4ygWvjELGnoOnVc,452
6
6
  pymammotion/aliyun/dataclass/connect_response.py,sha256=Yz-fEbDzgGPTo5Of2oAjmFkSv08T7ze80pQU4k-gKIU,824
@@ -35,7 +35,7 @@ pymammotion/data/model/rapid_state.py,sha256=_e9M-65AbkvIqXyMYzLKBxbNvpso42qD8R-
35
35
  pymammotion/data/model/region_data.py,sha256=75xOTM1qeRbSROp53eIczw3yCmYM9DgMjMh8qE9xkKo,2880
36
36
  pymammotion/data/model/report_info.py,sha256=1Rj_yRZ9apWX296QHae5prdObDbs32bsQf9rzMz2KEQ,4458
37
37
  pymammotion/data/mqtt/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
38
- pymammotion/data/mqtt/event.py,sha256=7hq-dl-HdKJB-TQ2kKfYfrebR_8qWE_lF2nQLlPyphU,3437
38
+ pymammotion/data/mqtt/event.py,sha256=j2bo__p7ROPPeiBH-74YyOAOMV7tlYYfl30nnZ81XgQ,3567
39
39
  pymammotion/data/mqtt/properties.py,sha256=HkBPghr26L9_b4QaOi1DtPgb0UoPIOGSe9wb3kgnM6Y,2815
40
40
  pymammotion/data/mqtt/status.py,sha256=zqnlo-MzejEQZszl0i0Wucoc3E76x6UtI9JLxoBnu54,1067
41
41
  pymammotion/data/state_manager.py,sha256=mNIAhP8f1Cb6-wFm2R5e-NlZauj-71iDGz8oZvdTq3Y,2826
@@ -58,10 +58,10 @@ pymammotion/mammotion/commands/messages/video.py,sha256=_8lJsU4sLm2CGnc7RDkueA0A
58
58
  pymammotion/mammotion/control/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
59
59
  pymammotion/mammotion/control/joystick.py,sha256=EWV20MMzQuhbLlNlXbsyZKSEpeM7x1CQL7saU4Pn0-g,6165
60
60
  pymammotion/mammotion/devices/__init__.py,sha256=T72jt0ejtMjo1rPmn_FeMF3pmp0LLeRRpc9WcDKEYYY,126
61
- pymammotion/mammotion/devices/mammotion.py,sha256=oYInls6l_DjGU0VwXersSpqJtXDrH6yObcQb3V_f8oc,47043
61
+ pymammotion/mammotion/devices/mammotion.py,sha256=Mml0L_eGUbLzJtQ97xThDpYzDhoaT6oDY9rHo8riAJ8,47868
62
62
  pymammotion/mqtt/__init__.py,sha256=Ocs5e-HLJvTuDpVXyECEsWIvwsUaxzj7lZ9mSYutNDY,105
63
63
  pymammotion/mqtt/mammotion_future.py,sha256=WKnHqeHiS2Ut-SaDBNOxqh1jDLeTiyLTsJ7PNUexrjk,687
64
- pymammotion/mqtt/mammotion_mqtt.py,sha256=K9TokiQWYJloWu5Hom00g7cfGhWHDSWqbcU9AqW4C9Q,8071
64
+ pymammotion/mqtt/mammotion_mqtt.py,sha256=7V0JW2N9dshUJAGlg6d6Y5LKWYoXvlQd0o-9l6idPNg,8071
65
65
  pymammotion/proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
66
  pymammotion/proto/basestation.proto,sha256=_x5gAz3FkZXS1jtq4GgZgaDCuRU-UV-7HTFdsfQ3zbo,1034
67
67
  pymammotion/proto/basestation.py,sha256=js64_N2xQYRxWPRdVNEapO0qe7vBlfYnjW5sE8hi7hw,2026
@@ -111,7 +111,7 @@ pymammotion/utility/device_type.py,sha256=KYawu2glZMVlPmxRbA4kVFujXz3miHp3rJiOWR
111
111
  pymammotion/utility/map.py,sha256=aoi-Luzuph02hKynTofMoq3mnPstanx75MDAVv49CuY,2211
112
112
  pymammotion/utility/periodic.py,sha256=9wJMfwXPlx6Mbp3Fws7LLTI34ZDKphH1bva_Ggyk32g,3281
113
113
  pymammotion/utility/rocker_util.py,sha256=syPL0QN4zMzHiTIkUKS7RXBBptjdbkfNlPddwUD5V3A,7171
114
- pymammotion-0.2.12.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
115
- pymammotion-0.2.12.dist-info/METADATA,sha256=1Mvxd071W8iz9hB4GG7VodeeUqHFslb-0p4l7dL4-IA,3969
116
- pymammotion-0.2.12.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
117
- pymammotion-0.2.12.dist-info/RECORD,,
114
+ pymammotion-0.2.14.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
115
+ pymammotion-0.2.14.dist-info/METADATA,sha256=mdcQH7AqMEKODoyghFU8tjC6Pw13xv6MK8QQCP_sXh4,3969
116
+ pymammotion-0.2.14.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
117
+ pymammotion-0.2.14.dist-info/RECORD,,