pymammotion 0.2.66__py3-none-any.whl → 0.2.68__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.
@@ -33,6 +33,7 @@ class MammotionBLE:
33
33
  device = await scanner.find_device_by_filter(scanCallback)
34
34
  if device is not None:
35
35
  return await self.create_client(device)
36
+ return False
36
37
 
37
38
  async def create_client(self, device: BLEDevice):
38
39
  self.client = BleakClient(device.address)
@@ -20,6 +20,7 @@ from pymammotion.proto import (
20
20
  dev_net_pb2,
21
21
  luba_msg_pb2,
22
22
  )
23
+ from pymammotion.proto.luba_msg import MsgCmdType, LubaMsg, MsgDevice, MsgAttr
23
24
  from pymammotion.utility.constant.device_constant import bleOrderCmd
24
25
 
25
26
  _LOGGER = logging.getLogger(__name__)
@@ -51,8 +52,8 @@ class BleMessage:
51
52
 
52
53
  def __init__(self, client: BleakClient) -> None:
53
54
  self.client = client
54
- self.mSendSequence = itertools.count()
55
- self.mReadSequence = itertools.count()
55
+ self.mSendSequence = itertools.count(start=0)
56
+ self.mReadSequence = itertools.count(start=0)
56
57
  self.mAck = queue.Queue()
57
58
  self.notification = BlufiNotifyData()
58
59
 
@@ -87,11 +88,11 @@ class BleMessage:
87
88
 
88
89
  async def send_device_info(self) -> None:
89
90
  """Currently not called"""
90
- luba_msg = luba_msg_pb2.LubaMsg(
91
- msgtype=luba_msg_pb2.MsgCmdType.MSG_CMD_TYPE_ESP,
92
- sender=luba_msg_pb2.MsgDevice.DEV_MOBILEAPP,
93
- rcver=luba_msg_pb2.MsgDevice.DEV_COMM_ESP,
94
- msgattr=luba_msg_pb2.MsgAttr.MSG_ATTR_REQ,
91
+ luba_msg = LubaMsg(
92
+ msgtype=MsgCmdType.MSG_CMD_TYPE_ESP,
93
+ sender=MsgDevice.DEV_MOBILEAPP,
94
+ rcver=MsgDevice.DEV_COMM_ESP,
95
+ msgattr=MsgAttr.MSG_ATTR_REQ,
95
96
  seqs=1,
96
97
  version=1,
97
98
  subtype=1,
@@ -140,69 +141,74 @@ class BleMessage:
140
141
  # if (this.mPrintDebug):
141
142
  # Log.d(TAG, "parseNotification Notification= " + Arrays.toString(response));
142
143
  # }
143
- if len(response) >= 4:
144
- # sequence = int(response[2]) # toInt
145
- # if sequence != next(self.mReadSequence):
146
- # _LOGGER.debug(
147
- # "parseNotification read sequence wrong",
148
- # sequence,
149
- # self.mReadSequence,
150
- # )
151
- # self.mReadSequence = itertools.count(start=sequence)
152
- # this is questionable
153
- # self.mReadSequence = sequence
154
- # self.mReadSequence_2.incrementAndGet()
155
-
156
- # LogUtil.m7773e(self.mGatt.getDevice().getName() + "打印丢包率", self.mReadSequence_2 + "/" + self.mReadSequence_1);
157
- pkt_type = int(response[0]) # toInt
158
- pkgType = self._getPackageType(pkt_type)
159
- subType = self._getSubType(pkt_type)
160
- self.notification.setType(pkt_type)
161
- self.notification.setPkgType(pkgType)
162
- self.notification.setSubType(subType)
163
- frameCtrl = int(response[1]) # toInt
164
- # _LOGGER.debug("frame ctrl")
165
- # _LOGGER.debug(frameCtrl)
166
- # _LOGGER.debug(response)
167
- # _LOGGER.debug(f"pktType {pkt_type} pkgType {pkgType} subType {subType}")
168
- self.notification.setFrameCtrl(frameCtrl)
169
- frameCtrlData = FrameCtrlData(frameCtrl)
170
- dataLen = int(response[3]) # toInt specifies length of data
171
-
172
- try:
173
- dataBytes = response[4 : 4 + dataLen]
174
- if frameCtrlData.isEncrypted():
175
- _LOGGER.debug("is encrypted")
176
- # BlufiAES aes = new BlufiAES(self.mAESKey, AES_TRANSFORMATION, generateAESIV(sequence));
177
- # dataBytes = aes.decrypt(dataBytes);
178
- # }
179
- if frameCtrlData.isChecksum():
180
- _LOGGER.debug("checksum")
181
- # int respChecksum1 = toInt(response[response.length - 1]);
182
- # int respChecksum2 = toInt(response[response.length - 2]);
183
- # int crc = BlufiCRC.calcCRC(BlufiCRC.calcCRC(0, new byte[]{(byte) sequence, (byte) dataLen}), dataBytes);
184
- # int calcChecksum1 = (crc >> 8) & 255;
185
- # int calcChecksum2 = crc & 255;
186
- # if (respChecksum1 != calcChecksum1 || respChecksum2 != calcChecksum2) {
187
- # Log.w(TAG, "parseNotification: read invalid checksum");
188
- # if (self.mPrintDebug) {
189
- # Log.d(TAG, "expect checksum: " + respChecksum1 + ", " + respChecksum2);
190
- # Log.d(TAG, "received checksum: " + calcChecksum1 + ", " + calcChecksum2);
191
- # return -4;
192
- # }
193
- # return -4;
194
- # }
195
- # }
196
- if frameCtrlData.hasFrag():
197
- dataOffset = 2
198
- else:
199
- dataOffset = 0
200
-
201
- self.notification.addData(dataBytes, dataOffset)
202
- return 1 if frameCtrlData.hasFrag() else 0
203
- except Exception as e:
204
- _LOGGER.debug(e)
205
- return -100
144
+ if len(response) < 4:
145
+ _LOGGER.debug("parseNotification data length less than 4")
146
+ return -2
147
+
148
+
149
+ sequence = int(response[2]) # toInt
150
+
151
+ # Compare with the second counter, mod 255
152
+ if sequence != (next(self.mReadSequence) & 255):
153
+ _LOGGER.debug(
154
+ "parseNotification read sequence wrong %s %s",
155
+ sequence,
156
+ self.mReadSequence,
157
+ )
158
+
159
+ # Set the value for mReadSequence manually
160
+ self.mReadSequence = itertools.count(start=sequence)
161
+
162
+ # LogUtil.m7773e(self.mGatt.getDevice().getName() + "打印丢包率", self.mReadSequence_2 + "/" + self.mReadSequence_1);
163
+ pkt_type = int(response[0]) # toInt
164
+ pkgType = self._getPackageType(pkt_type)
165
+ subType = self._getSubType(pkt_type)
166
+ self.notification.setType(pkt_type)
167
+ self.notification.setPkgType(pkgType)
168
+ self.notification.setSubType(subType)
169
+ frameCtrl = int(response[1]) # toInt
170
+ # _LOGGER.debug("frame ctrl")
171
+ # _LOGGER.debug(frameCtrl)
172
+ # _LOGGER.debug(response)
173
+ # _LOGGER.debug(f"pktType {pkt_type} pkgType {pkgType} subType {subType}")
174
+ self.notification.setFrameCtrl(frameCtrl)
175
+ frameCtrlData = FrameCtrlData(frameCtrl)
176
+ dataLen = int(response[3]) # toInt specifies length of data
177
+
178
+ try:
179
+ dataBytes = response[4 : 4 + dataLen]
180
+ if frameCtrlData.isEncrypted():
181
+ _LOGGER.debug("is encrypted")
182
+ # BlufiAES aes = new BlufiAES(self.mAESKey, AES_TRANSFORMATION, generateAESIV(sequence));
183
+ # dataBytes = aes.decrypt(dataBytes);
184
+ # }
185
+ if frameCtrlData.isChecksum():
186
+ _LOGGER.debug("checksum")
187
+ # int respChecksum1 = toInt(response[response.length - 1]);
188
+ # int respChecksum2 = toInt(response[response.length - 2]);
189
+ # int crc = BlufiCRC.calcCRC(BlufiCRC.calcCRC(0, new byte[]{(byte) sequence, (byte) dataLen}), dataBytes);
190
+ # int calcChecksum1 = (crc >> 8) & 255;
191
+ # int calcChecksum2 = crc & 255;
192
+ # if (respChecksum1 != calcChecksum1 || respChecksum2 != calcChecksum2) {
193
+ # Log.w(TAG, "parseNotification: read invalid checksum");
194
+ # if (self.mPrintDebug) {
195
+ # Log.d(TAG, "expect checksum: " + respChecksum1 + ", " + respChecksum2);
196
+ # Log.d(TAG, "received checksum: " + calcChecksum1 + ", " + calcChecksum2);
197
+ # return -4;
198
+ # }
199
+ # return -4;
200
+ # }
201
+ # }
202
+ if frameCtrlData.hasFrag():
203
+ dataOffset = 2
204
+ else:
205
+ dataOffset = 0
206
+
207
+ self.notification.addData(dataBytes, dataOffset)
208
+ return 1 if frameCtrlData.hasFrag() else 0
209
+ except Exception as e:
210
+ _LOGGER.debug(e)
211
+ return -100
206
212
 
207
213
  # Log.w(TAG, "parseNotification data length less than 4");
208
214
  return -2
@@ -162,36 +162,23 @@ class MessageNetwork:
162
162
  logger.debug(f"szNetwork: Send command - set network (on/off status). newWifiStatus={new_wifi_status}")
163
163
  return self.send_order_msg_net(build)
164
164
 
165
- def wifi_connectinfo_update(self, device_name: str, is_binary: bool) -> bytes:
166
- logger.debug(
167
- f"Send command - get Wifi connection information.wifiConnectinfoUpdate().deviceName={device_name}.isBinary={is_binary}"
165
+ def wifi_connectinfo_update(self) -> bytes:
166
+ build = dev_net_pb2.DevNet(
167
+ todev_ble_sync=1,
168
+ todev_WifiMsgUpload=dev_net_pb2.DrvWifiUpload(wifi_msg_upload=1),
168
169
  )
169
- if is_binary:
170
- build = dev_net_pb2.DevNet(
171
- todev_ble_sync=1,
172
- todev_WifiMsgUpload=dev_net_pb2.DrvWifiUpload(wifi_msg_upload=1),
173
- )
174
- logger.debug("Send command - get Wifi connection information")
175
- return self.send_order_msg_net(build)
176
- self.wifi_connectinfo_update2()
170
+ logger.debug("Send command - get Wifi connection information")
171
+ return self.send_order_msg_net(build)
177
172
 
178
173
  def wifi_connectinfo_update2(self) -> None:
179
174
  hash_map = {"getMsgCmd": 1}
180
175
  # self.post_custom_data(self.get_json_string(
181
176
  # 68, hash_map)) # ToDo: Fix this
182
177
 
183
- def get_record_wifi_list(self, is_binary: bool) -> bytes:
184
- logger.debug(f"getRecordWifiList().isBinary={is_binary}")
185
- if is_binary:
186
- build = dev_net_pb2.DevNet(todev_ble_sync=1, todev_WifiListUpload=dev_net_pb2.DrvWifiList())
187
- logger.debug("Send command - get memorized WiFi list upload command")
188
- return self.send_order_msg_net(build)
189
- self.get_record_wifi_list2()
190
-
191
- def get_record_wifi_list2(self) -> None:
192
- pass
193
- # self.messageNavigation.post_custom_data(
194
- # self.get_json_string(69)) # ToDo: Fix this
178
+ def get_record_wifi_list(self) -> bytes:
179
+ build = dev_net_pb2.DevNet(todev_ble_sync=1, todev_WifiListUpload=dev_net_pb2.DrvWifiList())
180
+ logger.debug("Send command - get memorized WiFi list upload command")
181
+ return self.send_order_msg_net(build)
195
182
 
196
183
  def close_clear_connect_current_wifi(self, ssid: str, status: int, is_binary: bool) -> bytes:
197
184
  if is_binary:
@@ -205,8 +192,8 @@ class MessageNetwork:
205
192
  return self.send_order_msg_net(build)
206
193
  self.close_clear_connect_current_wifi2(ssid, status)
207
194
 
208
- def close_clear_connect_current_wifi2(self, ssid: str, get_msg_cmd: int) -> None:
209
- data = {"ssid": ssid, "getMsgCmd": get_msg_cmd}
210
- # self.messageNavigation.post_custom_data(
211
- # ToDo: Fix this
212
- # self.get_json_string(bleOrderCmd.close_clear_connect_current_wifi, data).encode())
195
+ # def close_clear_connect_current_wifi2(self, ssid: str, get_msg_cmd: int) -> None:
196
+ # data = {"ssid": ssid, "getMsgCmd": get_msg_cmd}
197
+ # self.messageNavigation.post_custom_data(
198
+ # ToDo: Fix this
199
+ # self.get_json_string(bleOrderCmd.close_clear_connect_current_wifi, data).encode())
@@ -317,8 +317,13 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
317
317
  result = self._message.parseNotification(data)
318
318
  if result == 0:
319
319
  data = await self._message.parseBlufiNotifyData(True)
320
- self._update_raw_data(data)
321
- self._message.clearNotification()
320
+ try:
321
+ self._update_raw_data(data)
322
+ except (KeyError, ValueError, IndexError, UnicodeDecodeError):
323
+ _LOGGER.exception("Error parsing message %s", data)
324
+ finally:
325
+ self._message.clearNotification()
326
+
322
327
  _LOGGER.debug("%s: Received notification: %s", self.name, data)
323
328
  else:
324
329
  return
@@ -400,7 +405,6 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
400
405
  self._cancel_disconnect_timer()
401
406
  self._client = None
402
407
 
403
-
404
408
  def _disconnect_from_timer(self) -> None:
405
409
  """Disconnect from device."""
406
410
  if self._operation_lock.locked() and self._client.is_connected:
@@ -200,6 +200,7 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
200
200
  if self._ble_sync_task is None or self._ble_sync_task.cancelled():
201
201
  await self.run_periodic_sync_task()
202
202
  self.stopped = False
203
+ self._mqtt.on_ready_event.add_subscribers(self.on_ready)
203
204
  self.mqtt.connect_async()
204
205
 
205
206
  async def _ble_sync(self) -> None:
@@ -268,7 +269,7 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
268
269
  try:
269
270
  self._update_raw_data(binary_data)
270
271
  new_msg = LubaMsg().parse(binary_data)
271
- except (KeyError, ValueError, IndexError):
272
+ except (KeyError, ValueError, IndexError, UnicodeDecodeError):
272
273
  _LOGGER.exception("Error parsing message %s", binary_data)
273
274
 
274
275
  if (
@@ -286,7 +287,7 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
286
287
  if fut is None:
287
288
  return
288
289
  while fut.fut.cancelled() and len(self._mqtt.waiting_queue) > 0:
289
- fut: MammotionFuture = self.dequeue_by_iot_id(self._mqtt.waiting_queue, self.iot_id)
290
+ fut = self.dequeue_by_iot_id(self._mqtt.waiting_queue, self.iot_id)
290
291
  if not fut.fut.cancelled():
291
292
  fut.resolve(cast(bytes, binary_data))
292
293
  await self._state_manager.notification(new_msg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymammotion
3
- Version: 0.2.66
3
+ Version: 0.2.68
4
4
  Summary:
5
5
  License: GNU-3.0
6
6
  Author: Michael Arthur
@@ -11,8 +11,8 @@ pymammotion/aliyun/model/session_by_authcode_response.py,sha256=qW0pnnRXfyEuMbb9
11
11
  pymammotion/aliyun/model/stream_subscription_response.py,sha256=po765WASQDboVCosbPEfDHNlanBf-3WMrA6iV3ezooY,357
12
12
  pymammotion/aliyun/tmp_constant.py,sha256=M4Hq_lrGB3LZdX6R2XohRPFoK1NDnNV-pTJwJcJ9838,6650
13
13
  pymammotion/bluetooth/__init__.py,sha256=LAl8jqZ1fPh-3mLmViNQsP3s814C1vsocYUa6oSaXt0,36
14
- pymammotion/bluetooth/ble.py,sha256=YfkfEK3TLJ8BaidjAXfUVFv8reLCu6U_lYa3Bo0pddw,2449
15
- pymammotion/bluetooth/ble_message.py,sha256=XzsXcKv29GbGAnivYvZLfDOiMVAWsilk70N4TVwFl50,15448
14
+ pymammotion/bluetooth/ble.py,sha256=C7H7j71fhsvBfI8QEa9PlY3Ugm2CK1CXI7CXqranM48,2470
15
+ pymammotion/bluetooth/ble_message.py,sha256=k9yJBfZXA352rzA3csEQgk2prMNuM-r-0NPL1s1_f2c,15320
16
16
  pymammotion/bluetooth/const.py,sha256=CCqyHsYbB0BAYjwdhXt_n6eWWxmhlUrAFjvVv57mbvE,1749
17
17
  pymammotion/bluetooth/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  pymammotion/bluetooth/data/convert.py,sha256=6DMwvzVr9FWCoQFIKSI2poFXjISc_m6X59g8FlVO0-o,800
@@ -54,7 +54,7 @@ pymammotion/mammotion/commands/messages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5J
54
54
  pymammotion/mammotion/commands/messages/driver.py,sha256=DlOAC_yi1ycO5hKr5rfCpLmrqao6Mb6Fv1JWwMISnKE,3766
55
55
  pymammotion/mammotion/commands/messages/media.py,sha256=l-m4l2Vp1ZOHPHyJTceuLaLvdgHOEfmykkbDncCDUI4,1359
56
56
  pymammotion/mammotion/commands/messages/navigation.py,sha256=Z6RQK-pMh8o7_K_1yTENx3lkNBFQTU_ojunolSre0oM,23241
57
- pymammotion/mammotion/commands/messages/network.py,sha256=ooBiXgJC71lrkMeS_DLc3_pp7S8VGgyq7ZAmna-jKXw,8516
57
+ pymammotion/mammotion/commands/messages/network.py,sha256=HjB6oz4_g_vgYybuTuzCxIXmy83mgTAl9A0CBNuLTfI,7901
58
58
  pymammotion/mammotion/commands/messages/ota.py,sha256=g937HT_-OQXV6A3zUiZ53b45cOX6y-rzs5m-4b0IcTk,1473
59
59
  pymammotion/mammotion/commands/messages/system.py,sha256=pUdV8z-pnoXvDM29DQbfAi2mG6uK7EHQzJL2sWZLHrc,12843
60
60
  pymammotion/mammotion/commands/messages/video.py,sha256=ne1YSuQChaDFfmHgMO5Jc9_O_7vkt5yV1EXVEh3LTbg,1141
@@ -63,8 +63,8 @@ pymammotion/mammotion/control/joystick.py,sha256=QfBVxM_gxpWsZAGO90whtgxCI2tIZ3T
63
63
  pymammotion/mammotion/devices/__init__.py,sha256=f2qQFPgLGmV85W2hSlMUh5BYuht9o_Ar_JEAAMD4fsE,102
64
64
  pymammotion/mammotion/devices/base.py,sha256=F_L5aDtY6rgRkk7Q4CwilLenTANW6cBe9zIU3a9HRmA,10020
65
65
  pymammotion/mammotion/devices/mammotion.py,sha256=hSO184o1q4ftfLPx9froFPIXk428wGg8Ayw160W3z7c,12482
66
- pymammotion/mammotion/devices/mammotion_bluetooth.py,sha256=f_5ceoTS3aTwANwn1PxFejPQepotmB7RvK2IS3m4AUk,18700
67
- pymammotion/mammotion/devices/mammotion_cloud.py,sha256=MIBdakx7rvfrIqiVcq5Ry1qkqRVp1ykvU20vFW4Dg58,12006
66
+ pymammotion/mammotion/devices/mammotion_bluetooth.py,sha256=P4cJEfntCPcaGlrGGZSWEApM5D5cwCk4MbukfStSP3Q,18889
67
+ pymammotion/mammotion/devices/mammotion_cloud.py,sha256=7xbSZmC1PUG6ZfF5LtiELkQE61lybHoJcBUzz76VvLg,12074
68
68
  pymammotion/mqtt/__init__.py,sha256=Ocs5e-HLJvTuDpVXyECEsWIvwsUaxzj7lZ9mSYutNDY,105
69
69
  pymammotion/mqtt/mammotion_future.py,sha256=_OWqKOlUGl2yT1xOsXFQYpGd-1zQ63OxqXgy7KRQgYc,710
70
70
  pymammotion/mqtt/mammotion_mqtt.py,sha256=LaySave_hf0gU3crUTLqzpdQtxIwK8vu5DM8F8fbU2Y,8748
@@ -119,7 +119,7 @@ pymammotion/utility/map.py,sha256=GYscVMg2cX3IPlNpCBNHDW0S55yS1WGRf1iHnNZ7TfQ,22
119
119
  pymammotion/utility/movement.py,sha256=N75oAoAgFydqoaOedYIxGUHmuTCtPzAOtb-d_29tpfI,615
120
120
  pymammotion/utility/periodic.py,sha256=MbeSb9cfhxzYmdT_RiE0dZe3H9IfbQW_zSqhmSX2RUc,3321
121
121
  pymammotion/utility/rocker_util.py,sha256=6tX7sS87qoQC_tsxbx3NLL-HgS08wtzXiZkhDiz7uo0,7179
122
- pymammotion-0.2.66.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
123
- pymammotion-0.2.66.dist-info/METADATA,sha256=Z1GA-bm5h858zXFLIzEPY9GT4fy8PI9yfGXNuOpYrZk,3874
124
- pymammotion-0.2.66.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
125
- pymammotion-0.2.66.dist-info/RECORD,,
122
+ pymammotion-0.2.68.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
123
+ pymammotion-0.2.68.dist-info/METADATA,sha256=GPRAhITGV9-PrjCNA6PGJWm32nKPm_cHw5T-PqVbJwk,3874
124
+ pymammotion-0.2.68.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
125
+ pymammotion-0.2.68.dist-info/RECORD,,