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

@@ -9,7 +9,7 @@ import random
9
9
  import string
10
10
  import time
11
11
  import uuid
12
- from logging import getLogger
12
+ from logging import getLogger, exception
13
13
 
14
14
  from aiohttp import ClientSession
15
15
  from alibabacloud_iot_api_gateway.client import Client
@@ -45,6 +45,10 @@ MOVE_HEADERS = (
45
45
  )
46
46
 
47
47
 
48
+ class SetupException(Exception):
49
+ pass
50
+
51
+
48
52
  class CloudIOTGateway:
49
53
  """Class for interacting with Aliyun Cloud IoT Gateway."""
50
54
 
@@ -524,7 +528,8 @@ class CloudIOTGateway:
524
528
  str(response_body_dict.get("code")),
525
529
  str(response_body_dict.get("msg")),
526
530
  )
527
- return ""
531
+ if response_body_dict.get("code") == 29003:
532
+ raise SetupException(response_body_dict.get("code"))
528
533
 
529
534
  return message_id
530
535
 
@@ -40,6 +40,7 @@ from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
40
40
  from pymammotion.mqtt import MammotionMQTT
41
41
  from pymammotion.proto.luba_msg import LubaMsg
42
42
  from pymammotion.proto.mctrl_nav import NavGetCommDataAck, NavGetHashListAck
43
+ from pymammotion.utility.rocker_util import RockerControlUtil
43
44
 
44
45
 
45
46
  class CharacteristicMissingError(Exception):
@@ -116,8 +117,10 @@ async def _handle_retry(fut: asyncio.Future[None], func, command: bytes) -> None
116
117
 
117
118
  async def _handle_retry_cloud(fut: asyncio.Future[None], func, iotId: str, command: bytes) -> None:
118
119
  """Handle a retry."""
120
+
119
121
  if not fut.done():
120
- func(iotId, command)
122
+ loop = asyncio.get_running_loop()
123
+ await loop.run_in_executor(None, func, iotId, command)
121
124
 
122
125
 
123
126
  class ConnectionPreference(Enum):
@@ -223,10 +226,8 @@ class Mammotion(object):
223
226
 
224
227
  async def initiate_cloud_connection(self, cloud_client: CloudIOTGateway) -> None:
225
228
  if self._mammotion_mqtt is not None:
226
- if not self._mammotion_mqtt.is_connected:
227
- loop = asyncio.get_running_loop()
228
- await loop.run_in_executor(None, self._mammotion_mqtt.connect_async)
229
- return
229
+ if self._mammotion_mqtt.is_connected:
230
+ return
230
231
 
231
232
 
232
233
  self._mammotion_mqtt = MammotionMQTT(region_id=cloud_client._region.data.regionId,
@@ -244,6 +245,11 @@ class Mammotion(object):
244
245
  if device.deviceName.startswith(("Luba-", "Yuka-")):
245
246
  self.devices.add_device(MammotionMixedDeviceManager(name=device.deviceName, cloud_device=device, mqtt=self._mammotion_mqtt))
246
247
 
248
+ def set_disconnect_strategy(self, disconnect: bool):
249
+ for device_name, device in self.devices.devices:
250
+ if device.ble() is not None:
251
+ ble_device: MammotionBaseBLEDevice = device.ble()
252
+ ble_device.set_disconnect_strategy(disconnect)
247
253
 
248
254
  @staticmethod
249
255
  async def login(account: str, password: str) -> CloudIOTGateway:
@@ -504,6 +510,28 @@ class MammotionBaseDevice:
504
510
  # jobs list
505
511
  # hash_list_result = await self._send_command_with_args("get_all_boundary_hash_list", sub_cmd=3)
506
512
 
513
+ async def move_forward(self):
514
+ linear_speed = 1.0
515
+ angular_speed = 0.0
516
+ transfrom3 = RockerControlUtil.getInstance().transfrom3(90, 1000)
517
+ transform4 = RockerControlUtil.getInstance().transfrom3(0, 0)
518
+
519
+ if transfrom3 is not None and len(transfrom3) > 0:
520
+ linear_speed = transfrom3[0] * 10
521
+ angular_speed = int(transform4[1] * 4.5)
522
+ await self._send_command_with_args("send_movement", linear_speed=linear_speed, angular_speed=angular_speed)
523
+
524
+ async def move_stop(self):
525
+ linear_speed = 0.0
526
+ angular_speed = 0.0
527
+ transfrom3 = RockerControlUtil.getInstance().transfrom3(0, 0)
528
+ transform4 = RockerControlUtil.getInstance().transfrom3(0, 0)
529
+
530
+ if transfrom3 is not None and len(transfrom3) > 0:
531
+ linear_speed = transfrom3[0] * 10
532
+ angular_speed = int(transform4[1] * 4.5)
533
+ await self._send_command_with_args("send_movement", linear_speed=linear_speed, angular_speed=angular_speed)
534
+
507
535
  async def command(self, key: str, **kwargs):
508
536
  """Send a command to the device."""
509
537
  return await self._send_command_with_args(key, **kwargs)
@@ -515,6 +543,7 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
515
543
  def __init__(self, mowing_state: MowingDevice, device: BLEDevice, interface: int = 0, **kwargs: Any) -> None:
516
544
  """Initialize MammotionBaseBLEDevice."""
517
545
  super().__init__(mowing_state)
546
+ self._disconnect_strategy = True
518
547
  self._ble_sync_task = None
519
548
  self._prev_notification = None
520
549
  self._interface = f"hci{interface}"
@@ -621,7 +650,10 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
621
650
  @property
622
651
  def rssi(self) -> int:
623
652
  """Return RSSI of device."""
624
- return 0
653
+ try:
654
+ return self._mower.device.sys.toapp_report_data.connect.ble_rssi
655
+ finally:
656
+ return 0
625
657
 
626
658
  async def _ensure_connected(self):
627
659
  """Ensure connection to device is established."""
@@ -651,12 +683,11 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
651
683
  return
652
684
  _LOGGER.debug("%s: Connecting; RSSI: %s", self.name, self.rssi)
653
685
  client: BleakClientWithServiceCache = await establish_connection(
654
- BleakClient,
686
+ BleakClientWithServiceCache,
655
687
  self._device,
656
688
  self.name,
657
689
  self._disconnected,
658
690
  max_attempts=10,
659
- use_services_cache=True,
660
691
  ble_device_callback=lambda: self._device,
661
692
  )
662
693
  _LOGGER.debug("%s: Connected; RSSI: %s", self.name, self.rssi)
@@ -838,6 +869,8 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
838
869
 
839
870
  async def _execute_timed_disconnect(self) -> None:
840
871
  """Execute timed disconnection."""
872
+ if not self._disconnect_strategy:
873
+ return
841
874
  _LOGGER.debug(
842
875
  "%s: Executing timed disconnect after timeout of %s",
843
876
  self.name,
@@ -887,6 +920,9 @@ class MammotionBaseBLEDevice(MammotionBaseDevice):
887
920
  if self._client is not None:
888
921
  return await self._client.disconnect()
889
922
 
923
+ def set_disconnect_strategy(self, disconnect):
924
+ self._disconnect_strategy = disconnect
925
+
890
926
 
891
927
  class MammotionBaseCloudDevice(MammotionBaseDevice):
892
928
  """Base class for Mammotion Cloud devices."""
@@ -1003,7 +1039,7 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
1003
1039
  await loop.run_in_executor(None, self._mqtt_client.get_cloud_client().send_cloud_command, self.iot_id, command)
1004
1040
 
1005
1041
  retry_handle = self.loop.call_at(
1006
- self.loop.time() + 20,
1042
+ self.loop.time() + 10,
1007
1043
  lambda: asyncio.ensure_future(
1008
1044
  _handle_retry_cloud(
1009
1045
  self._notify_future, self._mqtt_client.get_cloud_client().send_cloud_command, self.iot_id, command
@@ -1,5 +1,5 @@
1
1
  """MammotionMQTT."""
2
-
2
+ import asyncio
3
3
  import hashlib
4
4
  import hmac
5
5
  import json
@@ -81,7 +81,7 @@ class MammotionMQTT:
81
81
  logger.info("Connecting...")
82
82
  self._linkkit_client.thing_setup()
83
83
  self._linkkit_client.connect_async()
84
- self._linkkit_client.start_worker_loop()
84
+
85
85
 
86
86
  def disconnect(self):
87
87
  """Disconnect from MQTT Server."""
@@ -91,6 +91,7 @@ class MammotionMQTT:
91
91
  def _thing_on_thing_enable(self, user_data):
92
92
  """Is called when Thing is enabled."""
93
93
  logger.debug("on_thing_enable")
94
+ self.is_connected = True
94
95
  # logger.debug('subscribe_topic, topic:%s' % echo_topic)
95
96
  # self._linkkit_client.subscribe_topic(echo_topic, 0)
96
97
  self._linkkit_client.subscribe_topic(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymammotion
3
- Version: 0.2.5
3
+ Version: 0.2.6
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=1-VgNDJCG1XJl-P3OnQ1FaKiF8OhAT0N-HMs0ZZV3WE,18427
3
+ pymammotion/aliyun/cloud_gateway.py,sha256=OkVsSF_zOVKOMcEKS88YOc6CUuXA2KjxDciP39hq7ts,18585
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
@@ -58,9 +58,9 @@ 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=M8DYRH0sSjGIM9hYmsSUCf4BHaJgNSwD3zdGeLiT118,43221
61
+ pymammotion/mammotion/devices/mammotion.py,sha256=qJeXMLDaQrizmDQNZ-BkHsiAqEfyODod-SVqyjWqV38,44807
62
62
  pymammotion/mqtt/__init__.py,sha256=Ocs5e-HLJvTuDpVXyECEsWIvwsUaxzj7lZ9mSYutNDY,105
63
- pymammotion/mqtt/mammotion_mqtt.py,sha256=DzNF29VCbIHa4SpUqH0mPgh_PiIDcPEX-Tx-l-YMh1k,7489
63
+ pymammotion/mqtt/mammotion_mqtt.py,sha256=jvYBLlwOzKWXmXpOL2zP7mTxleIYWzXfUXaGRLWUiCc,7488
64
64
  pymammotion/proto/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
65
65
  pymammotion/proto/basestation.proto,sha256=_x5gAz3FkZXS1jtq4GgZgaDCuRU-UV-7HTFdsfQ3zbo,1034
66
66
  pymammotion/proto/basestation.py,sha256=js64_N2xQYRxWPRdVNEapO0qe7vBlfYnjW5sE8hi7hw,2026
@@ -110,7 +110,7 @@ pymammotion/utility/device_type.py,sha256=KYawu2glZMVlPmxRbA4kVFujXz3miHp3rJiOWR
110
110
  pymammotion/utility/map.py,sha256=aoi-Luzuph02hKynTofMoq3mnPstanx75MDAVv49CuY,2211
111
111
  pymammotion/utility/periodic.py,sha256=9wJMfwXPlx6Mbp3Fws7LLTI34ZDKphH1bva_Ggyk32g,3281
112
112
  pymammotion/utility/rocker_util.py,sha256=syPL0QN4zMzHiTIkUKS7RXBBptjdbkfNlPddwUD5V3A,7171
113
- pymammotion-0.2.5.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
114
- pymammotion-0.2.5.dist-info/METADATA,sha256=6ykL_7ot9ackweOAJcco8C_LxfNsMWJNCvbH15RKuE0,3922
115
- pymammotion-0.2.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
116
- pymammotion-0.2.5.dist-info/RECORD,,
113
+ pymammotion-0.2.6.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
114
+ pymammotion-0.2.6.dist-info/METADATA,sha256=K4vtjnddoAb0UtgOT9VU3KDzLJksz6jDyjh0Ok0Q7Mc,3922
115
+ pymammotion-0.2.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
116
+ pymammotion-0.2.6.dist-info/RECORD,,