pymammotion 0.3.7__py3-none-any.whl → 0.4.0__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.
- pymammotion/__init__.py +2 -2
- pymammotion/aliyun/cloud_gateway.py +12 -9
- pymammotion/aliyun/model/aep_response.py +1 -2
- pymammotion/aliyun/model/dev_by_account_response.py +7 -8
- pymammotion/aliyun/model/login_by_oauth_response.py +2 -3
- pymammotion/aliyun/model/regions_response.py +3 -3
- pymammotion/aliyun/model/session_by_authcode_response.py +1 -2
- pymammotion/aliyun/model/stream_subscription_response.py +1 -2
- pymammotion/bluetooth/ble.py +5 -5
- pymammotion/bluetooth/ble_message.py +9 -13
- pymammotion/data/model/device.py +31 -228
- pymammotion/data/model/device_config.py +0 -10
- pymammotion/data/model/device_info.py +13 -0
- pymammotion/data/model/device_limits.py +49 -0
- pymammotion/data/model/generate_route_information.py +1 -1
- pymammotion/data/model/hash_list.py +6 -2
- pymammotion/data/model/plan.py +0 -3
- pymammotion/data/model/raw_data.py +215 -0
- pymammotion/data/model/region_data.py +10 -11
- pymammotion/data/model/report_info.py +1 -1
- pymammotion/data/mqtt/event.py +18 -14
- pymammotion/data/mqtt/properties.py +1 -1
- pymammotion/data/mqtt/status.py +1 -1
- pymammotion/data/state_manager.py +83 -23
- pymammotion/http/encryption.py +220 -0
- pymammotion/http/http.py +92 -39
- pymammotion/http/model/http.py +4 -2
- pymammotion/mammotion/commands/abstract_message.py +2 -2
- pymammotion/mammotion/commands/messages/driver.py +28 -21
- pymammotion/mammotion/commands/messages/media.py +10 -14
- pymammotion/mammotion/commands/messages/navigation.py +14 -11
- pymammotion/mammotion/commands/messages/network.py +17 -14
- pymammotion/mammotion/commands/messages/ota.py +9 -14
- pymammotion/mammotion/commands/messages/system.py +32 -29
- pymammotion/mammotion/commands/messages/video.py +9 -14
- pymammotion/mammotion/devices/base.py +7 -14
- pymammotion/mammotion/devices/mammotion.py +22 -13
- pymammotion/mammotion/devices/mammotion_bluetooth.py +15 -4
- pymammotion/mammotion/devices/mammotion_cloud.py +30 -12
- pymammotion/mqtt/linkkit/__init__.py +5 -0
- pymammotion/mqtt/linkkit/h2client.py +585 -0
- pymammotion/mqtt/linkkit/linkkit.py +3020 -0
- pymammotion/mqtt/mammotion_mqtt.py +13 -9
- pymammotion/proto/__init__.py +2176 -1
- pymammotion/proto/luba_mul.proto +1 -0
- pymammotion/proto/luba_mul_pb2.py +8 -8
- pymammotion/proto/luba_mul_pb2.pyi +1 -0
- pymammotion/proto/mctrl_nav_pb2.py +69 -67
- pymammotion/proto/mctrl_nav_pb2.pyi +13 -5
- pymammotion/proto/mctrl_sys_pb2.py +41 -37
- pymammotion/proto/mctrl_sys_pb2.pyi +34 -11
- pymammotion/utility/constant/device_constant.py +14 -5
- pymammotion/utility/device_config.py +754 -0
- pymammotion/utility/device_type.py +64 -16
- {pymammotion-0.3.7.dist-info → pymammotion-0.4.0.dist-info}/METADATA +9 -9
- {pymammotion-0.3.7.dist-info → pymammotion-0.4.0.dist-info}/RECORD +58 -62
- {pymammotion-0.3.7.dist-info → pymammotion-0.4.0.dist-info}/WHEEL +1 -1
- pymammotion/aliyun/cloud_service.py +0 -65
- pymammotion/proto/basestation.py +0 -59
- pymammotion/proto/common.py +0 -12
- pymammotion/proto/dev_net.py +0 -381
- pymammotion/proto/luba_msg.py +0 -81
- pymammotion/proto/luba_mul.py +0 -76
- pymammotion/proto/mctrl_driver.py +0 -100
- pymammotion/proto/mctrl_nav.py +0 -664
- pymammotion/proto/mctrl_ota.py +0 -48
- pymammotion/proto/mctrl_pept.py +0 -41
- pymammotion/proto/mctrl_sys.py +0 -574
- {pymammotion-0.3.7.dist-info → pymammotion-0.4.0.dist-info}/LICENSE +0 -0
@@ -1,10 +1,11 @@
|
|
1
1
|
import asyncio
|
2
|
+
from asyncio import TimerHandle
|
2
3
|
import base64
|
4
|
+
from collections import deque
|
5
|
+
from collections.abc import Awaitable, Callable
|
3
6
|
import json
|
4
7
|
import logging
|
5
|
-
from
|
6
|
-
from collections import deque
|
7
|
-
from typing import Any, Awaitable, Callable, Optional, cast
|
8
|
+
from typing import Any, cast
|
8
9
|
|
9
10
|
import betterproto
|
10
11
|
|
@@ -13,13 +14,13 @@ from pymammotion.aliyun.cloud_gateway import DeviceOfflineException
|
|
13
14
|
from pymammotion.aliyun.model.dev_by_account_response import Device
|
14
15
|
from pymammotion.data.mqtt.event import ThingEventMessage
|
15
16
|
from pymammotion.data.mqtt.properties import ThingPropertiesMessage
|
17
|
+
from pymammotion.data.mqtt.status import ThingStatusMessage
|
16
18
|
from pymammotion.data.state_manager import StateManager
|
17
19
|
from pymammotion.event.event import DataEvent
|
18
20
|
from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
|
19
21
|
from pymammotion.mammotion.devices.base import MammotionBaseDevice
|
20
22
|
from pymammotion.mqtt.mammotion_future import MammotionFuture
|
21
|
-
from pymammotion.proto import has_field
|
22
|
-
from pymammotion.proto.luba_msg import LubaMsg
|
23
|
+
from pymammotion.proto import LubaMsg, has_field
|
23
24
|
|
24
25
|
_LOGGER = logging.getLogger(__name__)
|
25
26
|
|
@@ -35,6 +36,7 @@ class MammotionCloud:
|
|
35
36
|
self._waiting_queue = deque()
|
36
37
|
self.mqtt_message_event = DataEvent()
|
37
38
|
self.mqtt_properties_event = DataEvent()
|
39
|
+
self.mqtt_status_event = DataEvent()
|
38
40
|
self.on_ready_event = DataEvent()
|
39
41
|
self.on_disconnected_event = DataEvent()
|
40
42
|
self.on_connected_event = DataEvent()
|
@@ -116,7 +118,7 @@ class MammotionCloud:
|
|
116
118
|
json_str = json.dumps(payload)
|
117
119
|
payload = json.loads(json_str)
|
118
120
|
|
119
|
-
await self.
|
121
|
+
await self._parse_mqtt_response(topic, payload)
|
120
122
|
|
121
123
|
async def _parse_mqtt_response(self, topic: str, payload: dict) -> None:
|
122
124
|
"""Parse the MQTT response."""
|
@@ -134,10 +136,9 @@ class MammotionCloud:
|
|
134
136
|
if event.method == "thing.properties":
|
135
137
|
await self.mqtt_properties_event.data_event(event)
|
136
138
|
_LOGGER.debug(event)
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
await self._parse_mqtt_response(topic=topic, payload=payload)
|
139
|
+
elif topic.endswith("/app/down/thing/status"):
|
140
|
+
status = ThingStatusMessage.from_dict(payload)
|
141
|
+
await self.mqtt_status_event.data_event(status)
|
141
142
|
|
142
143
|
def _disconnect(self) -> None:
|
143
144
|
"""Disconnect the MQTT client."""
|
@@ -156,7 +157,7 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
|
|
156
157
|
super().__init__(state_manager, cloud_device)
|
157
158
|
self._ble_sync_task: TimerHandle | None = None
|
158
159
|
self.stopped = False
|
159
|
-
self.on_ready_callback:
|
160
|
+
self.on_ready_callback: Callable[[], Awaitable[None]] | None = None
|
160
161
|
self.loop = asyncio.get_event_loop()
|
161
162
|
self._mqtt = mqtt
|
162
163
|
self.iot_id = cloud_device.iotId
|
@@ -166,9 +167,12 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
|
|
166
167
|
self.currentID = ""
|
167
168
|
self._mqtt.mqtt_message_event.add_subscribers(self._parse_message_for_device)
|
168
169
|
self._mqtt.mqtt_properties_event.add_subscribers(self._parse_message_properties_for_device)
|
170
|
+
self._mqtt.mqtt_status_event.add_subscribers(self._parse_message_status_for_device)
|
169
171
|
self._mqtt.on_ready_event.add_subscribers(self.on_ready)
|
170
172
|
self._mqtt.on_disconnected_event.add_subscribers(self.on_disconnect)
|
171
173
|
self._mqtt.on_connected_event.add_subscribers(self.on_connect)
|
174
|
+
self._state_manager.cloud_gethash_ack_callback = self.datahash_response
|
175
|
+
self._state_manager.cloud_get_commondata_ack_callback = self.commdata_response
|
172
176
|
self.set_queue_callback(self.queue_command)
|
173
177
|
|
174
178
|
if self._mqtt.is_ready:
|
@@ -179,9 +183,17 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
|
|
179
183
|
self._mqtt.on_disconnected_event.remove_subscribers(self.on_disconnect)
|
180
184
|
self._mqtt.on_connected_event.remove_subscribers(self.on_connect)
|
181
185
|
self._mqtt.mqtt_message_event.remove_subscribers(self._parse_message_for_device)
|
186
|
+
self._state_manager.cloud_gethash_ack_callback = None
|
187
|
+
self._state_manager.cloud_get_commondata_ack_callback = None
|
182
188
|
if self._ble_sync_task:
|
183
189
|
self._ble_sync_task.cancel()
|
184
190
|
|
191
|
+
def set_notification_callback(self, func: Callable[[tuple[str, Any | None]], Awaitable[None]]) -> None:
|
192
|
+
self._state_manager.cloud_on_notification_callback = func
|
193
|
+
|
194
|
+
def set_queue_callback(self, func: Callable[[str, dict[str, Any]], Awaitable[bytes]]) -> None:
|
195
|
+
self._state_manager.cloud_queue_command_callback = func
|
196
|
+
|
185
197
|
async def on_ready(self) -> None:
|
186
198
|
"""Callback for when MQTT is subscribed to events."""
|
187
199
|
if self.stopped:
|
@@ -278,6 +290,11 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
|
|
278
290
|
return
|
279
291
|
self.state_manager.properties(event)
|
280
292
|
|
293
|
+
async def _parse_message_status_for_device(self, status: ThingStatusMessage) -> None:
|
294
|
+
if status.params.iotId != self.iot_id:
|
295
|
+
return
|
296
|
+
self.state_manager.status(status)
|
297
|
+
|
281
298
|
async def _parse_message_for_device(self, event: ThingEventMessage) -> None:
|
282
299
|
_LOGGER.debug("_parse_message_for_device")
|
283
300
|
params = event.params
|
@@ -301,6 +318,8 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
|
|
301
318
|
if new_msg.net.todev_ble_sync != 0 or has_field(new_msg.net.toapp_wifi_iot_status):
|
302
319
|
return
|
303
320
|
|
321
|
+
await self._state_manager.notification(new_msg)
|
322
|
+
|
304
323
|
if len(self._mqtt.waiting_queue) > 0:
|
305
324
|
fut: MammotionFuture = self.dequeue_by_iot_id(self._mqtt.waiting_queue, self.iot_id)
|
306
325
|
if fut is None:
|
@@ -309,7 +328,6 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
|
|
309
328
|
fut = self.dequeue_by_iot_id(self._mqtt.waiting_queue, self.iot_id)
|
310
329
|
if not fut.fut.cancelled():
|
311
330
|
fut.resolve(cast(bytes, binary_data))
|
312
|
-
await self._state_manager.notification(new_msg)
|
313
331
|
|
314
332
|
@property
|
315
333
|
def mqtt(self):
|