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

Files changed (54) hide show
  1. pymammotion/__init__.py +3 -3
  2. pymammotion/aliyun/cloud_gateway.py +114 -18
  3. pymammotion/aliyun/model/dev_by_account_response.py +169 -21
  4. pymammotion/const.py +3 -0
  5. pymammotion/data/model/device.py +1 -0
  6. pymammotion/data/model/device_config.py +1 -1
  7. pymammotion/data/model/enums.py +5 -3
  8. pymammotion/data/model/generate_route_information.py +2 -2
  9. pymammotion/data/model/hash_list.py +113 -33
  10. pymammotion/data/model/region_data.py +4 -4
  11. pymammotion/data/{state_manager.py → mower_state_manager.py} +17 -7
  12. pymammotion/data/mqtt/event.py +47 -22
  13. pymammotion/data/mqtt/mammotion_properties.py +257 -0
  14. pymammotion/data/mqtt/properties.py +32 -29
  15. pymammotion/data/mqtt/status.py +17 -16
  16. pymammotion/homeassistant/__init__.py +3 -0
  17. pymammotion/homeassistant/mower_api.py +446 -0
  18. pymammotion/homeassistant/rtk_api.py +54 -0
  19. pymammotion/http/http.py +392 -16
  20. pymammotion/http/model/http.py +82 -2
  21. pymammotion/http/model/response_factory.py +10 -4
  22. pymammotion/mammotion/commands/mammotion_command.py +6 -0
  23. pymammotion/mammotion/commands/messages/navigation.py +10 -6
  24. pymammotion/mammotion/devices/__init__.py +27 -3
  25. pymammotion/mammotion/devices/base.py +16 -139
  26. pymammotion/mammotion/devices/mammotion.py +361 -203
  27. pymammotion/mammotion/devices/mammotion_bluetooth.py +7 -5
  28. pymammotion/mammotion/devices/mammotion_cloud.py +42 -83
  29. pymammotion/mammotion/devices/mammotion_mower_ble.py +49 -0
  30. pymammotion/mammotion/devices/mammotion_mower_cloud.py +39 -0
  31. pymammotion/mammotion/devices/managers/managers.py +81 -0
  32. pymammotion/mammotion/devices/mower_device.py +121 -0
  33. pymammotion/mammotion/devices/mower_manager.py +107 -0
  34. pymammotion/mammotion/devices/rtk_ble.py +89 -0
  35. pymammotion/mammotion/devices/rtk_cloud.py +113 -0
  36. pymammotion/mammotion/devices/rtk_device.py +50 -0
  37. pymammotion/mammotion/devices/rtk_manager.py +122 -0
  38. pymammotion/mqtt/__init__.py +2 -1
  39. pymammotion/mqtt/aliyun_mqtt.py +232 -0
  40. pymammotion/mqtt/mammotion_mqtt.py +174 -192
  41. pymammotion/mqtt/mqtt_models.py +66 -0
  42. pymammotion/proto/__init__.py +1 -1
  43. pymammotion/proto/mctrl_nav.proto +1 -1
  44. pymammotion/proto/mctrl_nav_pb2.py +1 -1
  45. pymammotion/proto/mctrl_nav_pb2.pyi +4 -4
  46. pymammotion/proto/mctrl_sys.proto +1 -1
  47. pymammotion/utility/datatype_converter.py +13 -12
  48. pymammotion/utility/device_type.py +88 -3
  49. pymammotion/utility/mur_mur_hash.py +132 -87
  50. {pymammotion-0.5.32.dist-info → pymammotion-0.5.45.dist-info}/METADATA +25 -31
  51. {pymammotion-0.5.32.dist-info → pymammotion-0.5.45.dist-info}/RECORD +59 -45
  52. {pymammotion-0.5.32.dist-info → pymammotion-0.5.45.dist-info}/WHEEL +1 -1
  53. pymammotion/http/_init_.py +0 -0
  54. {pymammotion-0.5.32.dist-info → pymammotion-0.5.45.dist-info/licenses}/LICENSE +0 -0
@@ -44,6 +44,12 @@ class MammotionCommand(
44
44
  # 1 multipoint turn
45
45
  return self.read_write_device(6, context, 1)
46
46
 
47
+ def get_error_code(self) -> bytes:
48
+ return self.read_write_device(5, 2, 1)
49
+
50
+ def get_error_timestamp(self) -> bytes:
51
+ return self.read_write_device(5, 3, 1)
52
+
47
53
  def get_device_product_key(self) -> str:
48
54
  return self._product_key
49
55
 
@@ -33,7 +33,7 @@ logger = logging.getLogger(__name__)
33
33
 
34
34
 
35
35
  class MessageNavigation(AbstractMessage, ABC):
36
- def send_order_msg_nav(self, build) -> bytes:
36
+ def send_order_msg_nav(self, build: MctlNav) -> bytes:
37
37
  luba_msg = LubaMsg(
38
38
  msgtype=MsgCmdType.NAV,
39
39
  sender=MsgDevice.DEV_MOBILEAPP,
@@ -206,9 +206,9 @@ class MessageNavigation(AbstractMessage, ABC):
206
206
  reserved=plan_bean.reserved,
207
207
  weeks=plan_bean.weeks,
208
208
  start_date=plan_bean.start_date,
209
- trigger_type=plan_bean.job_type,
210
- day=plan_bean.interval_days,
211
- toward_included_angle=plan_bean.demond_angle,
209
+ trigger_type=plan_bean.trigger_type,
210
+ day=plan_bean.day,
211
+ toward_included_angle=plan_bean.toward_included_angle,
212
212
  toward_mode=0,
213
213
  )
214
214
  logger.debug(f"Send read job plan command planBean={plan_bean}")
@@ -262,7 +262,7 @@ class MessageNavigation(AbstractMessage, ABC):
262
262
  toapp_map_name_msg=NavMapNameMsg(
263
263
  hash=0,
264
264
  result=0,
265
- device_id=device_id, # iotId or ???
265
+ device_id=device_id, # iot_id
266
266
  rw=0,
267
267
  )
268
268
  )
@@ -390,7 +390,7 @@ class MessageNavigation(AbstractMessage, ABC):
390
390
  generate_route_information}")
391
391
  return self.send_order_msg_nav(MctlNav(bidire_reqconver_path=build))
392
392
 
393
- def modify_generate_route_information(self, generate_route_information: GenerateRouteInformation) -> bytes:
393
+ def modify_route_information(self, generate_route_information: GenerateRouteInformation) -> bytes:
394
394
  logger.debug(f"Generate route data source: {generate_route_information}")
395
395
  build = NavReqCoverPath(
396
396
  pver=1,
@@ -432,7 +432,11 @@ class MessageNavigation(AbstractMessage, ABC):
432
432
  return self.send_order_msg_nav(build)
433
433
 
434
434
  def get_line_info_list(self, hash_list: list[int], transaction_id: int) -> bytes:
435
+ """Get route information (mow path) corresponding to the specified hash list based on time.
436
+ e.g transaction_id = int(time.time() * 1000)
437
+ """
435
438
  logger.debug(f"Sending==========Get route command: {hash_list}")
439
+
436
440
  build = MctlNav(
437
441
  app_request_cover_paths=AppRequestCoverPathsT(
438
442
  pver=1, hash_list=hash_list, transaction_id=transaction_id, sub_cmd=0
@@ -1,5 +1,29 @@
1
- """mqtt init."""
1
+ """Mammotion devices module."""
2
2
 
3
- from .mammotion import MammotionBaseBLEDevice
3
+ from .mammotion import Mammotion, MammotionDeviceManager
4
+ from .mammotion_bluetooth import MammotionBaseBLEDevice
5
+ from .mammotion_cloud import MammotionBaseCloudDevice, MammotionCloud
6
+ from .mammotion_mower_ble import MammotionMowerBLEDevice
7
+ from .mammotion_mower_cloud import MammotionMowerCloudDevice
8
+ from .mower_device import MammotionMowerDevice
9
+ from .mower_manager import MammotionMowerDeviceManager
10
+ from .rtk_ble import MammotionRTKBLEDevice
11
+ from .rtk_cloud import MammotionRTKCloudDevice
12
+ from .rtk_device import MammotionRTKDevice
13
+ from .rtk_manager import MammotionRTKDeviceManager
4
14
 
5
- __all__ = ["MammotionBaseBLEDevice"]
15
+ __all__ = [
16
+ "Mammotion",
17
+ "MammotionDeviceManager",
18
+ "MammotionMowerDeviceManager",
19
+ "MammotionBaseBLEDevice",
20
+ "MammotionBaseCloudDevice",
21
+ "MammotionCloud",
22
+ "MammotionMowerBLEDevice",
23
+ "MammotionMowerCloudDevice",
24
+ "MammotionMowerDevice",
25
+ "MammotionRTKBLEDevice",
26
+ "MammotionRTKCloudDevice",
27
+ "MammotionRTKDevice",
28
+ "MammotionRTKDeviceManager",
29
+ ]
@@ -1,41 +1,23 @@
1
- from abc import abstractmethod
1
+ from abc import ABC, abstractmethod
2
2
  import asyncio
3
3
  import logging
4
- import time
5
4
  from typing import Any
6
5
 
7
6
  import betterproto2
8
7
 
9
8
  from pymammotion.aliyun.model.dev_by_account_response import Device
10
- from pymammotion.data.model import RegionData
11
9
  from pymammotion.data.model.device import MowingDevice
12
10
  from pymammotion.data.model.raw_data import RawMowerData
13
- from pymammotion.data.state_manager import StateManager
14
- from pymammotion.proto import LubaMsg, NavGetCommDataAck, NavGetHashListAck, NavPlanJobSet, SvgMessageAckT
15
- from pymammotion.utility.device_type import DeviceType
11
+ from pymammotion.data.mower_state_manager import MowerStateManager
12
+ from pymammotion.proto import LubaMsg
16
13
 
17
14
  _LOGGER = logging.getLogger(__name__)
18
15
 
19
16
 
20
- def find_next_integer(lst: list[int], current_hash: int) -> int | None:
21
- try:
22
- # Find the index of the current integer
23
- current_index = lst.index(current_hash)
24
-
25
- # Check if there is a next integer in the list
26
- if current_index + 1 < len(lst):
27
- return lst[current_index + 1]
28
- else:
29
- return None # Or raise an exception or handle it in some other way
30
- except ValueError:
31
- # Handle the case where current_int is not in the list
32
- return None # Or raise an exception or handle it in some other way
33
-
34
-
35
- class MammotionBaseDevice:
17
+ class MammotionBaseDevice(ABC):
36
18
  """Base class for Mammotion devices."""
37
19
 
38
- def __init__(self, state_manager: StateManager, cloud_device: Device) -> None:
20
+ def __init__(self, state_manager: MowerStateManager, cloud_device: Device) -> None:
39
21
  """Initialize MammotionBaseDevice."""
40
22
  self.loop = asyncio.get_event_loop()
41
23
  self._state_manager = state_manager
@@ -44,57 +26,6 @@ class MammotionBaseDevice:
44
26
  self._notify_future: asyncio.Future[bytes] | None = None
45
27
  self._cloud_device = cloud_device
46
28
 
47
- async def datahash_response(self, hash_ack: NavGetHashListAck) -> None:
48
- """Handle datahash responses for root level hashs."""
49
- current_frame = hash_ack.current_frame
50
-
51
- missing_frames = self.mower.map.missing_root_hash_frame(hash_ack)
52
- if len(missing_frames) == 0:
53
- if len(self.mower.map.missing_hashlist(hash_ack.sub_cmd)) > 0:
54
- data_hash = self.mower.map.missing_hashlist(hash_ack.sub_cmd).pop(0)
55
- await self.queue_command("synchronize_hash_data", hash_num=data_hash)
56
- return
57
-
58
- if current_frame != missing_frames[0] - 1:
59
- current_frame = missing_frames[0] - 1
60
- await self.queue_command("get_hash_response", total_frame=hash_ack.total_frame, current_frame=current_frame)
61
-
62
- async def commdata_response(self, common_data: NavGetCommDataAck | SvgMessageAckT) -> None:
63
- """Handle common data responses."""
64
- total_frame = common_data.total_frame
65
- current_frame = common_data.current_frame
66
-
67
- missing_frames = self.mower.map.missing_frame(common_data)
68
- if len(missing_frames) == 0:
69
- # get next in hash ack list
70
-
71
- data_hash = (
72
- self.mower.map.missing_hashlist(common_data.sub_cmd).pop(0)
73
- if len(self.mower.map.missing_hashlist(common_data.sub_cmd)) > 0
74
- else None
75
- )
76
- if data_hash is None:
77
- return
78
-
79
- await self.queue_command("synchronize_hash_data", hash_num=data_hash)
80
- else:
81
- if current_frame != missing_frames[0] - 1:
82
- current_frame = missing_frames[0] - 1
83
-
84
- region_data = RegionData()
85
- region_data.hash = common_data.data_hash if isinstance(common_data, SvgMessageAckT) else common_data.hash
86
- region_data.action = common_data.action if isinstance(common_data, NavGetCommDataAck) else None
87
- region_data.type = common_data.type
88
- region_data.sub_cmd = common_data.sub_cmd
89
- region_data.total_frame = total_frame
90
- region_data.current_frame = current_frame
91
- await self.queue_command("get_regional_data", regional_data=region_data)
92
-
93
- async def plan_callback(self, plan: NavPlanJobSet) -> None:
94
- if plan.plan_index < plan.total_plan_num - 1:
95
- index = plan.plan_index + 1
96
- await self.queue_command("read_plan", sub_cmd=2, plan_index=index)
97
-
98
29
  def _update_raw_data(self, data: bytes) -> None:
99
30
  """Update raw and model data from notifications."""
100
31
  tmp_msg = LubaMsg().parse(data)
@@ -128,7 +59,7 @@ class MammotionBaseDevice:
128
59
  nav[nav_sub_msg[0]] = nav_sub_msg[1].to_dict(casing=betterproto2.Casing.SNAKE)
129
60
  self._raw_data["nav"] = nav
130
61
 
131
- def _update_sys_data(self, tmp_msg) -> None:
62
+ def _update_sys_data(self, tmp_msg: LubaMsg) -> None:
132
63
  """Update system data."""
133
64
  sys_sub_msg = betterproto2.which_one_of(tmp_msg.sys, "SubSysMsg")
134
65
  if sys_sub_msg[1] is None:
@@ -138,7 +69,7 @@ class MammotionBaseDevice:
138
69
  sys[sys_sub_msg[0]] = sys_sub_msg[1].to_dict(casing=betterproto2.Casing.SNAKE)
139
70
  self._raw_data["sys"] = sys
140
71
 
141
- def _update_driver_data(self, tmp_msg) -> None:
72
+ def _update_driver_data(self, tmp_msg: LubaMsg) -> None:
142
73
  """Update driver data."""
143
74
  drv_sub_msg = betterproto2.which_one_of(tmp_msg.driver, "SubDrvMsg")
144
75
  if drv_sub_msg[1] is None:
@@ -148,7 +79,7 @@ class MammotionBaseDevice:
148
79
  drv[drv_sub_msg[0]] = drv_sub_msg[1].to_dict(casing=betterproto2.Casing.SNAKE)
149
80
  self._raw_data["driver"] = drv
150
81
 
151
- def _update_net_data(self, tmp_msg) -> None:
82
+ def _update_net_data(self, tmp_msg: LubaMsg) -> None:
152
83
  """Update network data."""
153
84
  net_sub_msg = betterproto2.which_one_of(tmp_msg.net, "NetSubType")
154
85
  if net_sub_msg[1] is None:
@@ -161,7 +92,7 @@ class MammotionBaseDevice:
161
92
  net[net_sub_msg[0]] = net_sub_msg[1].to_dict(casing=betterproto2.Casing.SNAKE)
162
93
  self._raw_data["net"] = net
163
94
 
164
- def _update_mul_data(self, tmp_msg) -> None:
95
+ def _update_mul_data(self, tmp_msg: LubaMsg) -> None:
165
96
  """Update mul data."""
166
97
  mul_sub_msg = betterproto2.which_one_of(tmp_msg.mul, "SubMul")
167
98
  if mul_sub_msg[1] is None:
@@ -171,7 +102,7 @@ class MammotionBaseDevice:
171
102
  mul[mul_sub_msg[0]] = mul_sub_msg[1].to_dict(casing=betterproto2.Casing.SNAKE)
172
103
  self._raw_data["mul"] = mul
173
104
 
174
- def _update_ota_data(self, tmp_msg) -> None:
105
+ def _update_ota_data(self, tmp_msg: LubaMsg) -> None:
175
106
  """Update OTA data."""
176
107
  ota_sub_msg = betterproto2.which_one_of(tmp_msg.ota, "SubOtaMsg")
177
108
  if ota_sub_msg[1] is None:
@@ -192,71 +123,17 @@ class MammotionBaseDevice:
192
123
  return self._state_manager.get_device()
193
124
 
194
125
  @abstractmethod
195
- async def queue_command(self, key: str, **kwargs: any) -> bytes | None:
126
+ async def queue_command(self, key: str, **kwargs: Any) -> None:
196
127
  """Queue commands to mower."""
197
128
 
198
129
  @abstractmethod
199
- async def _ble_sync(self):
130
+ async def _ble_sync(self) -> None:
200
131
  """Send ble sync command every 3 seconds or sooner."""
201
132
 
202
133
  @abstractmethod
203
- def stop(self):
134
+ def stop(self) -> None:
204
135
  """Stop everything ready for destroying."""
205
136
 
206
- async def start_sync(self, retry: int) -> None:
207
- """Start synchronization with the device."""
208
- await self.queue_command("get_device_base_info")
209
- await self.queue_command("get_device_product_model")
210
- await self.queue_command("get_report_cfg")
211
- """RTK and dock location."""
212
- await self.queue_command("read_write_device", rw_id=5, context=1, rw=1)
213
- await self.async_read_settings()
214
-
215
- async def start_map_sync(self) -> None:
216
- """Start sync of map data."""
217
-
218
- self.mower.map.update_hash_lists(self.mower.map.hashlist)
219
-
220
- await self.queue_command("send_todev_ble_sync", sync_type=3)
221
-
222
- if self._cloud_device and len(self.mower.map.area_name) == 0 and not DeviceType.is_luba1(self.mower.name):
223
- await self.queue_command("get_area_name_list", device_id=self._cloud_device.iotId)
224
-
225
- if len(self.mower.map.plan) == 0 or list(self.mower.map.plan.values())[0].total_plan_num != len(
226
- self.mower.map.plan
227
- ):
228
- await self.queue_command("read_plan", sub_cmd=2, plan_index=0)
229
-
230
- for hash_id, frame in list(self.mower.map.area.items()):
231
- missing_frames = self.mower.map.find_missing_frames(frame)
232
- if len(missing_frames) > 0:
233
- del self.mower.map.area[hash_id]
234
-
235
- for hash_id, frame in list(self.mower.map.path.items()):
236
- missing_frames = self.mower.map.find_missing_frames(frame)
237
- if len(missing_frames) > 0:
238
- del self.mower.map.path[hash_id]
239
-
240
- for hash_id, frame in list(self.mower.map.obstacle.items()):
241
- missing_frames = self.mower.map.find_missing_frames(frame)
242
- if len(missing_frames) > 0:
243
- del self.mower.map.obstacle[hash_id]
244
-
245
- # don't know why but total frame on svg is wrong
246
- # for hash, frame in self.mower.map.svg.items():
247
- # missing_frames = self.mower.map.find_missing_frames(frame)
248
- # if len(missing_frames) > 0:
249
- # del self.mower.map.svg[hash]
250
-
251
- if len(self.mower.map.root_hash_lists) == 0 or len(self.mower.map.missing_hashlist()) > 0:
252
- await self.queue_command("get_all_boundary_hash_list", sub_cmd=0)
253
-
254
- # sub_cmd 3 is job hashes??
255
- # sub_cmd 4 is dump location (yuka)
256
- # jobs list
257
- #
258
- # await self.queue_command("get_all_boundary_hash_list", sub_cmd=3)
259
-
260
137
  async def async_read_settings(self) -> None:
261
138
  """Read settings from device."""
262
139
  # no cutting in rain nav_sys_param_cmd (id 3 context 1/0)
@@ -277,10 +154,10 @@ class MammotionBaseDevice:
277
154
  await self.queue_command("read_write_device", rw_id=5, rw=1, context=2)
278
155
  await self.queue_command("read_write_device", rw_id=5, rw=1, context=3)
279
156
 
280
- async def command(self, key: str, **kwargs):
157
+ async def command(self, key: str, **kwargs: Any) -> None:
281
158
  """Send a command to the device."""
282
- return await self.queue_command(key, **kwargs)
159
+ await self.queue_command(key, **kwargs)
283
160
 
284
161
  @property
285
- def state_manager(self):
162
+ def state_manager(self) -> MowerStateManager:
286
163
  return self._state_manager