pymammotion 0.5.69__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.
Files changed (154) hide show
  1. pymammotion/__init__.py +53 -0
  2. pymammotion/agora/__init__.py +0 -0
  3. pymammotion/agora/agora_api.py +755 -0
  4. pymammotion/agora/agora_rtc_capabilities.py +748 -0
  5. pymammotion/agora/agora_websockets.py +1175 -0
  6. pymammotion/aliyun/__init__.py +1 -0
  7. pymammotion/aliyun/client.py +235 -0
  8. pymammotion/aliyun/cloud_gateway.py +982 -0
  9. pymammotion/aliyun/model/aep_response.py +21 -0
  10. pymammotion/aliyun/model/connect_response.py +51 -0
  11. pymammotion/aliyun/model/dev_by_account_response.py +195 -0
  12. pymammotion/aliyun/model/login_by_oauth_response.py +64 -0
  13. pymammotion/aliyun/model/regions_response.py +29 -0
  14. pymammotion/aliyun/model/session_by_authcode_response.py +19 -0
  15. pymammotion/aliyun/model/thing_response.py +12 -0
  16. pymammotion/aliyun/regions.py +62 -0
  17. pymammotion/aliyun/tea/core.py +297 -0
  18. pymammotion/aliyun/tmp_constant.py +171 -0
  19. pymammotion/bluetooth/__init__.py +1 -0
  20. pymammotion/bluetooth/ble.py +62 -0
  21. pymammotion/bluetooth/ble_message.py +676 -0
  22. pymammotion/bluetooth/const.py +27 -0
  23. pymammotion/bluetooth/data/__init__.py +0 -0
  24. pymammotion/bluetooth/data/convert.py +25 -0
  25. pymammotion/bluetooth/data/framectrldata.py +40 -0
  26. pymammotion/bluetooth/data/notifydata.py +62 -0
  27. pymammotion/bluetooth/model/__init__.py +0 -0
  28. pymammotion/bluetooth/model/atomic_integer.py +54 -0
  29. pymammotion/const.py +13 -0
  30. pymammotion/data/__init__.py +0 -0
  31. pymammotion/data/model/__init__.py +8 -0
  32. pymammotion/data/model/account.py +8 -0
  33. pymammotion/data/model/device.py +192 -0
  34. pymammotion/data/model/device_config.py +72 -0
  35. pymammotion/data/model/device_info.py +60 -0
  36. pymammotion/data/model/device_limits.py +49 -0
  37. pymammotion/data/model/enums.py +77 -0
  38. pymammotion/data/model/errors.py +12 -0
  39. pymammotion/data/model/events.py +14 -0
  40. pymammotion/data/model/generate_geojson.py +565 -0
  41. pymammotion/data/model/generate_route_information.py +26 -0
  42. pymammotion/data/model/hash_list.py +475 -0
  43. pymammotion/data/model/location.py +36 -0
  44. pymammotion/data/model/mowing_modes.py +77 -0
  45. pymammotion/data/model/rapid_state.py +45 -0
  46. pymammotion/data/model/raw_data.py +215 -0
  47. pymammotion/data/model/region_data.py +102 -0
  48. pymammotion/data/model/report_info.py +182 -0
  49. pymammotion/data/model/work.py +27 -0
  50. pymammotion/data/mower_state_manager.py +369 -0
  51. pymammotion/data/mqtt/__init__.py +1 -0
  52. pymammotion/data/mqtt/event.py +227 -0
  53. pymammotion/data/mqtt/mammotion_properties.py +276 -0
  54. pymammotion/data/mqtt/properties.py +203 -0
  55. pymammotion/data/mqtt/status.py +57 -0
  56. pymammotion/event/__init__.py +6 -0
  57. pymammotion/event/event.py +96 -0
  58. pymammotion/homeassistant/__init__.py +3 -0
  59. pymammotion/homeassistant/mower_api.py +514 -0
  60. pymammotion/homeassistant/rtk_api.py +54 -0
  61. pymammotion/http/__init__.py +0 -0
  62. pymammotion/http/encryption.py +220 -0
  63. pymammotion/http/http.py +673 -0
  64. pymammotion/http/model/__init__.py +0 -0
  65. pymammotion/http/model/camera_stream.py +31 -0
  66. pymammotion/http/model/http.py +249 -0
  67. pymammotion/http/model/response_factory.py +61 -0
  68. pymammotion/http/model/rtk.py +16 -0
  69. pymammotion/mammotion/__init__.py +0 -0
  70. pymammotion/mammotion/commands/__init__.py +0 -0
  71. pymammotion/mammotion/commands/abstract_message.py +24 -0
  72. pymammotion/mammotion/commands/mammotion_command.py +81 -0
  73. pymammotion/mammotion/commands/messages/__init__.py +0 -0
  74. pymammotion/mammotion/commands/messages/basestation.py +43 -0
  75. pymammotion/mammotion/commands/messages/driver.py +122 -0
  76. pymammotion/mammotion/commands/messages/media.py +87 -0
  77. pymammotion/mammotion/commands/messages/navigation.py +564 -0
  78. pymammotion/mammotion/commands/messages/network.py +205 -0
  79. pymammotion/mammotion/commands/messages/ota.py +38 -0
  80. pymammotion/mammotion/commands/messages/system.py +330 -0
  81. pymammotion/mammotion/commands/messages/video.py +33 -0
  82. pymammotion/mammotion/control/__init__.py +0 -0
  83. pymammotion/mammotion/control/joystick.py +145 -0
  84. pymammotion/mammotion/devices/__init__.py +29 -0
  85. pymammotion/mammotion/devices/base.py +163 -0
  86. pymammotion/mammotion/devices/mammotion.py +571 -0
  87. pymammotion/mammotion/devices/mammotion_bluetooth.py +496 -0
  88. pymammotion/mammotion/devices/mammotion_cloud.py +355 -0
  89. pymammotion/mammotion/devices/mammotion_mower_ble.py +48 -0
  90. pymammotion/mammotion/devices/mammotion_mower_cloud.py +39 -0
  91. pymammotion/mammotion/devices/managers/managers.py +81 -0
  92. pymammotion/mammotion/devices/mower_device.py +120 -0
  93. pymammotion/mammotion/devices/mower_manager.py +107 -0
  94. pymammotion/mammotion/devices/rtk_ble.py +89 -0
  95. pymammotion/mammotion/devices/rtk_cloud.py +115 -0
  96. pymammotion/mammotion/devices/rtk_device.py +50 -0
  97. pymammotion/mammotion/devices/rtk_manager.py +125 -0
  98. pymammotion/mqtt/__init__.py +6 -0
  99. pymammotion/mqtt/aliyun_mqtt.py +237 -0
  100. pymammotion/mqtt/linkkit/__init__.py +5 -0
  101. pymammotion/mqtt/linkkit/h2client.py +585 -0
  102. pymammotion/mqtt/linkkit/linkkit.py +3025 -0
  103. pymammotion/mqtt/mammotion_future.py +26 -0
  104. pymammotion/mqtt/mammotion_mqtt.py +214 -0
  105. pymammotion/mqtt/mqtt_models.py +66 -0
  106. pymammotion/proto/__init__.py +4841 -0
  107. pymammotion/proto/basestation.proto +51 -0
  108. pymammotion/proto/basestation_pb2.py +35 -0
  109. pymammotion/proto/basestation_pb2.pyi +89 -0
  110. pymammotion/proto/common.proto +7 -0
  111. pymammotion/proto/common_pb2.py +25 -0
  112. pymammotion/proto/common_pb2.pyi +13 -0
  113. pymammotion/proto/dev_net.proto +321 -0
  114. pymammotion/proto/dev_net_pb2.py +111 -0
  115. pymammotion/proto/dev_net_pb2.pyi +515 -0
  116. pymammotion/proto/luba_msg.proto +76 -0
  117. pymammotion/proto/luba_msg_pb2.py +41 -0
  118. pymammotion/proto/luba_msg_pb2.pyi +97 -0
  119. pymammotion/proto/luba_mul.proto +129 -0
  120. pymammotion/proto/luba_mul_pb2.py +61 -0
  121. pymammotion/proto/luba_mul_pb2.pyi +178 -0
  122. pymammotion/proto/mctrl_driver.proto +107 -0
  123. pymammotion/proto/mctrl_driver_pb2.py +57 -0
  124. pymammotion/proto/mctrl_driver_pb2.pyi +167 -0
  125. pymammotion/proto/mctrl_nav.proto +591 -0
  126. pymammotion/proto/mctrl_nav_pb2.py +136 -0
  127. pymammotion/proto/mctrl_nav_pb2.pyi +1067 -0
  128. pymammotion/proto/mctrl_ota.proto +80 -0
  129. pymammotion/proto/mctrl_ota_pb2.py +45 -0
  130. pymammotion/proto/mctrl_ota_pb2.pyi +128 -0
  131. pymammotion/proto/mctrl_pept.proto +34 -0
  132. pymammotion/proto/mctrl_pept_pb2.py +33 -0
  133. pymammotion/proto/mctrl_pept_pb2.pyi +58 -0
  134. pymammotion/proto/mctrl_sys.proto +741 -0
  135. pymammotion/proto/mctrl_sys_pb2.py +206 -0
  136. pymammotion/proto/mctrl_sys_pb2.pyi +1213 -0
  137. pymammotion/proto/message_pool.py +3 -0
  138. pymammotion/proto/py.typed +0 -0
  139. pymammotion/py.typed +0 -0
  140. pymammotion/utility/constant/__init__.py +3 -0
  141. pymammotion/utility/constant/device_constant.py +315 -0
  142. pymammotion/utility/conversions.py +5 -0
  143. pymammotion/utility/datatype_converter.py +124 -0
  144. pymammotion/utility/device_config.py +755 -0
  145. pymammotion/utility/device_type.py +489 -0
  146. pymammotion/utility/map.py +259 -0
  147. pymammotion/utility/movement.py +18 -0
  148. pymammotion/utility/mur_mur_hash.py +159 -0
  149. pymammotion/utility/periodic.py +106 -0
  150. pymammotion/utility/rocker_util.py +194 -0
  151. pymammotion-0.5.69.dist-info/METADATA +93 -0
  152. pymammotion-0.5.69.dist-info/RECORD +154 -0
  153. pymammotion-0.5.69.dist-info/WHEEL +4 -0
  154. pymammotion-0.5.69.dist-info/licenses/LICENSE +674 -0
@@ -0,0 +1,107 @@
1
+ from __future__ import annotations
2
+
3
+ from bleak import BLEDevice
4
+
5
+ from pymammotion import CloudIOTGateway
6
+ from pymammotion.aliyun.model.dev_by_account_response import Device
7
+ from pymammotion.data.model.device import MowingDevice
8
+ from pymammotion.data.model.enums import ConnectionPreference
9
+ from pymammotion.data.mower_state_manager import MowerStateManager
10
+ from pymammotion.mammotion.devices.mammotion_cloud import MammotionCloud
11
+ from pymammotion.mammotion.devices.mammotion_mower_ble import MammotionMowerBLEDevice
12
+ from pymammotion.mammotion.devices.mammotion_mower_cloud import MammotionMowerCloudDevice
13
+ from pymammotion.mammotion.devices.managers.managers import AbstractDeviceManager
14
+
15
+
16
+ class MammotionMowerDeviceManager(AbstractDeviceManager):
17
+ def __init__(
18
+ self,
19
+ name: str,
20
+ iot_id: str,
21
+ cloud_client: CloudIOTGateway,
22
+ cloud_device: Device,
23
+ ble_device: BLEDevice | None = None,
24
+ mqtt: MammotionCloud | None = None,
25
+ preference: ConnectionPreference = ConnectionPreference.BLUETOOTH,
26
+ ) -> None:
27
+ super().__init__(name, iot_id, cloud_client, cloud_device, preference)
28
+ self._ble_device: MammotionMowerBLEDevice | None = None
29
+ self._cloud_device: MammotionMowerCloudDevice | None = None
30
+
31
+ self._state_manager = MowerStateManager(MowingDevice())
32
+ self._state_manager.get_device().name = name
33
+ self.add_ble(ble_device) if ble_device else None
34
+ self.add_cloud(mqtt) if mqtt else None
35
+
36
+ @property
37
+ def state_manager(self) -> MowerStateManager:
38
+ """Return the state manager."""
39
+ return self._state_manager
40
+
41
+ @property
42
+ def state(self) -> MowingDevice:
43
+ """Return the state of the device."""
44
+ return self._state_manager.get_device()
45
+
46
+ @state.setter
47
+ def state(self, value: MowingDevice) -> None:
48
+ self._state_manager.set_device(value)
49
+
50
+ @property
51
+ def ble(self) -> MammotionMowerBLEDevice | None:
52
+ return self._ble_device
53
+
54
+ @property
55
+ def cloud(self) -> MammotionMowerCloudDevice | None:
56
+ return self._cloud_device
57
+
58
+ def has_queued_commands(self) -> bool:
59
+ if self.cloud and self.preference == ConnectionPreference.WIFI:
60
+ return not self.cloud.mqtt.command_queue.empty()
61
+ elif self.ble:
62
+ return not self.ble.command_queue.empty()
63
+ return False
64
+
65
+ def add_ble(self, ble_device: BLEDevice) -> MammotionMowerBLEDevice:
66
+ self._ble_device = MammotionMowerBLEDevice(
67
+ state_manager=self._state_manager, cloud_device=self._device, device=ble_device
68
+ )
69
+ return self._ble_device
70
+
71
+ def add_cloud(self, mqtt: MammotionCloud) -> MammotionMowerCloudDevice:
72
+ self._cloud_device = MammotionMowerCloudDevice(
73
+ mqtt, cloud_device=self._device, state_manager=self._state_manager
74
+ )
75
+ return self._cloud_device
76
+
77
+ def replace_cloud(self, cloud_device: MammotionMowerCloudDevice) -> None:
78
+ self._cloud_device = cloud_device
79
+
80
+ def remove_cloud(self) -> None:
81
+ self._state_manager.cloud_get_commondata_ack_callback = None
82
+ self._state_manager.cloud_get_hashlist_ack_callback = None
83
+ self._state_manager.cloud_get_plan_callback = None
84
+ self._state_manager.cloud_on_notification_callback = None
85
+ self._state_manager.cloud_gethash_ack_callback = None
86
+ self._cloud_device = None
87
+
88
+ def replace_ble(self, ble_device: MammotionMowerBLEDevice) -> None:
89
+ self._ble_device = ble_device
90
+
91
+ def remove_ble(self) -> None:
92
+ self._state_manager.ble_get_commondata_ack_callback = None
93
+ self._state_manager.ble_get_hashlist_ack_callback = None
94
+ self._state_manager.ble_get_plan_callback = None
95
+ self._state_manager.ble_on_notification_callback = None
96
+ self._state_manager.ble_gethash_ack_callback = None
97
+ self._ble_device = None
98
+
99
+ def replace_mqtt(self, mqtt: MammotionCloud) -> None:
100
+ device = self._cloud_device.device
101
+ self._cloud_device = MammotionMowerCloudDevice(mqtt, cloud_device=device, state_manager=self._state_manager)
102
+
103
+ def has_cloud(self) -> bool:
104
+ return self._cloud_device is not None
105
+
106
+ def has_ble(self) -> bool:
107
+ return self._ble_device is not None
@@ -0,0 +1,89 @@
1
+ """RTK device with Bluetooth LE connectivity."""
2
+
3
+ import asyncio
4
+ import logging
5
+ from typing import Any
6
+ from uuid import UUID
7
+
8
+ from bleak import BleakGATTCharacteristic, BLEDevice
9
+ from bleak_retry_connector import BleakClientWithServiceCache
10
+
11
+ from pymammotion.aliyun.model.dev_by_account_response import Device
12
+ from pymammotion.bluetooth import BleMessage
13
+ from pymammotion.data.model.device import RTKDevice
14
+ from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
15
+ from pymammotion.mammotion.devices.rtk_device import MammotionRTKDevice
16
+
17
+ _LOGGER = logging.getLogger(__name__)
18
+
19
+
20
+ class MammotionRTKBLEDevice(MammotionRTKDevice):
21
+ """RTK device with BLE connectivity - simpler than mowers, no map sync."""
22
+
23
+ def __init__(
24
+ self, cloud_device: Device, rtk_state: RTKDevice, device: BLEDevice, interface: int = 0, **kwargs: Any
25
+ ) -> None:
26
+ """Initialize MammotionRTKBLEDevice."""
27
+ super().__init__(cloud_device, rtk_state)
28
+ self.command_sent_time = 0
29
+ self._disconnect_strategy = True
30
+ self._interface = f"hci{interface}"
31
+ self.ble_device = device
32
+ self._client: BleakClientWithServiceCache | None = None
33
+ self._read_char: BleakGATTCharacteristic | int | str | UUID = 0
34
+ self._write_char: BleakGATTCharacteristic | int | str | UUID = 0
35
+ self._disconnect_timer: asyncio.TimerHandle | None = None
36
+ self._message: BleMessage | None = None
37
+ self._commands: MammotionCommand = MammotionCommand(device.name or "", 1)
38
+ self.command_queue = asyncio.Queue()
39
+ self._expected_disconnect = False
40
+ self._connect_lock = asyncio.Lock()
41
+ self._operation_lock = asyncio.Lock()
42
+ self._key: str | None = None
43
+ loop = asyncio.get_event_loop()
44
+ loop.create_task(self.process_queue())
45
+
46
+ def __del__(self) -> None:
47
+ """Cleanup."""
48
+ if self._disconnect_timer:
49
+ self._disconnect_timer.cancel()
50
+
51
+ @property
52
+ def client(self) -> BleakClientWithServiceCache:
53
+ """Return the BLE client."""
54
+ return self._client
55
+
56
+ def set_disconnect_strategy(self, *, disconnect: bool) -> None:
57
+ """Set disconnect strategy."""
58
+ self._disconnect_strategy = disconnect
59
+
60
+ async def process_queue(self) -> None:
61
+ """Process queued commands - simplified for RTK."""
62
+ while True:
63
+ key, kwargs = await self.command_queue.get()
64
+ try:
65
+ _LOGGER.debug("Processing RTK BLE command: %s", key)
66
+ command_bytes = getattr(self._commands, key)(**kwargs)
67
+ # Send command via BLE (implementation depends on BLE infrastructure)
68
+ # For now, this is a placeholder
69
+ _LOGGER.debug("RTK BLE command sent: %s", key)
70
+ except Exception as ex:
71
+ _LOGGER.exception("Error processing RTK BLE command: %s", ex)
72
+ finally:
73
+ self.command_queue.task_done()
74
+
75
+ async def queue_command(self, key: str, **kwargs: Any) -> None:
76
+ """Queue a command to the RTK device."""
77
+ await self.command_queue.put((key, kwargs))
78
+
79
+ async def command(self, key: str, **kwargs):
80
+ """Send a command to the RTK device."""
81
+ return await self.queue_command(key, **kwargs)
82
+
83
+ async def _ble_sync(self) -> None:
84
+ """RTK devices don't use BLE sync in the same way as mowers."""
85
+
86
+ async def stop(self) -> None:
87
+ """Stop everything ready for destroying."""
88
+ if self._client is not None and self._client.is_connected:
89
+ await self._client.disconnect()
@@ -0,0 +1,115 @@
1
+ """RTK device with cloud MQTT connectivity."""
2
+
3
+ import asyncio
4
+ from collections.abc import Awaitable, Callable
5
+ import logging
6
+ from typing import Any
7
+
8
+ from pymammotion.aliyun.model.dev_by_account_response import Device
9
+ from pymammotion.data.model.device import RTKDevice
10
+ from pymammotion.data.mqtt.properties import ThingPropertiesMessage
11
+ from pymammotion.data.mqtt.status import ThingStatusMessage
12
+ from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
13
+ from pymammotion.mammotion.devices.mammotion_cloud import MammotionCloud
14
+ from pymammotion.mammotion.devices.rtk_device import MammotionRTKDevice
15
+
16
+ _LOGGER = logging.getLogger(__name__)
17
+
18
+
19
+ class MammotionRTKCloudDevice(MammotionRTKDevice):
20
+ """RTK device with cloud connectivity - simpler than mowers, no map sync."""
21
+
22
+ def __init__(self, mqtt: MammotionCloud, cloud_device: Device, rtk_state: RTKDevice) -> None:
23
+ """Initialize MammotionRTKCloudDevice.
24
+ :rtype: None
25
+ """
26
+ super().__init__(cloud_device, rtk_state)
27
+ self.stopped = False
28
+ self.on_ready_callback: Callable[[], Awaitable[None]] | None = None
29
+ self.loop = asyncio.get_event_loop()
30
+ self._mqtt = mqtt
31
+ self.iot_id = cloud_device.iot_id
32
+ self.device = cloud_device
33
+ self._commands: MammotionCommand = MammotionCommand(
34
+ cloud_device.device_name,
35
+ int(mqtt.cloud_client.mammotion_http.response.data.userInformation.userAccount),
36
+ )
37
+ # Subscribe to MQTT events for this device
38
+ self._mqtt.mqtt_properties_event.add_subscribers(self._parse_message_properties_for_device)
39
+ self._mqtt.mqtt_status_event.add_subscribers(self._parse_message_status_for_device)
40
+ self._mqtt.on_ready_event.add_subscribers(self.on_ready)
41
+ self._mqtt.on_disconnected_event.add_subscribers(self.on_disconnect)
42
+ self._mqtt.on_connected_event.add_subscribers(self.on_connect)
43
+
44
+ def __del__(self) -> None:
45
+ """Cleanup subscriptions."""
46
+ if hasattr(self, "_mqtt"):
47
+ self._mqtt.on_ready_event.remove_subscribers(self.on_ready)
48
+ self._mqtt.on_disconnected_event.remove_subscribers(self.on_disconnect)
49
+ self._mqtt.on_connected_event.remove_subscribers(self.on_connect)
50
+ self._mqtt.mqtt_properties_event.remove_subscribers(self._parse_message_properties_for_device)
51
+ self._mqtt.mqtt_status_event.remove_subscribers(self._parse_message_status_for_device)
52
+
53
+ @property
54
+ def command_sent_time(self) -> float:
55
+ return self._mqtt.command_sent_time
56
+
57
+ @property
58
+ def mqtt(self) -> MammotionCloud:
59
+ return self._mqtt
60
+
61
+ async def on_ready(self) -> None:
62
+ """Callback for when MQTT is subscribed to events."""
63
+ if self.stopped:
64
+ return
65
+ if self.on_ready_callback:
66
+ await self.on_ready_callback()
67
+
68
+ async def on_disconnect(self) -> None:
69
+ """Callback for when MQTT disconnects."""
70
+ self._mqtt.disconnect()
71
+
72
+ async def on_connect(self) -> None:
73
+ """Callback for when MQTT connects."""
74
+
75
+ def stop(self) -> None:
76
+ """Stop all tasks and disconnect."""
77
+ self.stopped = True
78
+
79
+ async def start(self) -> None:
80
+ """Start the device connection."""
81
+ self.stopped = False
82
+ if not self.mqtt.is_connected():
83
+ loop = asyncio.get_running_loop()
84
+ await loop.run_in_executor(None, self.mqtt.connect_async)
85
+
86
+ async def queue_command(self, key: str, **kwargs: Any) -> None:
87
+ """Queue a command to the RTK device."""
88
+ _LOGGER.debug("Queueing command: %s", key)
89
+ future = asyncio.Future()
90
+ command_bytes = getattr(self._commands, key)(**kwargs)
91
+ await self._mqtt.command_queue.put((self.iot_id, key, command_bytes, future))
92
+ try:
93
+ await future
94
+ except asyncio.CancelledError:
95
+ """Try again once."""
96
+ future = asyncio.Future()
97
+ await self._mqtt.command_queue.put((self.iot_id, key, command_bytes, future))
98
+
99
+ async def _parse_message_properties_for_device(self, event: ThingPropertiesMessage) -> None:
100
+ """Parse property messages for this RTK device."""
101
+ if event.params.iot_id != self.iot_id:
102
+ return
103
+ # RTK devices have simpler properties - update as needed
104
+ _LOGGER.debug("RTK properties update: %s", event)
105
+
106
+ async def _parse_message_status_for_device(self, status: ThingStatusMessage) -> None:
107
+ """Parse status messages for this RTK device."""
108
+ if status.params.iot_id != self.iot_id:
109
+ return
110
+ # Update online status
111
+ self._rtk_device.online = True
112
+ _LOGGER.debug("RTK status update: %s", status)
113
+
114
+ async def _ble_sync(self) -> None:
115
+ """RTK devices don't use BLE sync in the same way as mowers."""
@@ -0,0 +1,50 @@
1
+ """RTK device class without map synchronization callbacks."""
2
+
3
+ import asyncio
4
+ import logging
5
+ from typing import Any
6
+
7
+ from pymammotion.aliyun.model.dev_by_account_response import Device
8
+ from pymammotion.data.model.device import RTKDevice
9
+ from pymammotion.data.model.raw_data import RawMowerData
10
+
11
+ _LOGGER = logging.getLogger(__name__)
12
+
13
+
14
+ class MammotionRTKDevice:
15
+ """RTK device without map synchronization - simpler than mowers."""
16
+
17
+ def __init__(self, cloud_device: Device, rtk_state: RTKDevice) -> None:
18
+ """Initialize MammotionRTKDevice."""
19
+ self.loop = asyncio.get_event_loop()
20
+ self._rtk_device = rtk_state
21
+ self._raw_data = dict()
22
+ self._raw_mower_data: RawMowerData = RawMowerData()
23
+ self._notify_future: asyncio.Future[bytes] | None = None
24
+ self._cloud_device = cloud_device
25
+
26
+ @property
27
+ def rtk(self) -> RTKDevice:
28
+ """Get the RTK device state."""
29
+ return self._rtk_device
30
+
31
+ @property
32
+ def raw_data(self) -> dict[str, Any]:
33
+ """Get the raw data of the device."""
34
+ return self._raw_data
35
+
36
+ async def command(self, key: str, **kwargs: Any) -> bytes | None:
37
+ """Send a command to the device."""
38
+ return await self.queue_command(key, **kwargs)
39
+
40
+ async def queue_command(self, key: str, **kwargs: Any) -> bytes | None:
41
+ """Queue commands to RTK device - to be implemented by connection-specific subclasses."""
42
+ raise NotImplementedError("Subclasses must implement queue_command")
43
+
44
+ async def _ble_sync(self) -> None:
45
+ """Send ble sync command - to be implemented by connection-specific subclasses."""
46
+ raise NotImplementedError("Subclasses must implement _ble_sync")
47
+
48
+ def stop(self) -> None:
49
+ """Stop everything ready for destroying - to be implemented by connection-specific subclasses."""
50
+ raise NotImplementedError("Subclasses must implement stop")
@@ -0,0 +1,125 @@
1
+ """RTK Device Manager - manages RTK devices with cloud and BLE connectivity."""
2
+
3
+ from typing import override
4
+
5
+ from bleak import BLEDevice
6
+
7
+ from pymammotion.aliyun.cloud_gateway import CloudIOTGateway
8
+ from pymammotion.aliyun.model.dev_by_account_response import Device
9
+ from pymammotion.data.model.device import RTKDevice
10
+ from pymammotion.data.model.enums import ConnectionPreference
11
+ from pymammotion.mammotion.devices.mammotion_cloud import MammotionCloud
12
+ from pymammotion.mammotion.devices.managers.managers import AbstractDeviceManager
13
+ from pymammotion.mammotion.devices.rtk_ble import MammotionRTKBLEDevice
14
+ from pymammotion.mammotion.devices.rtk_cloud import MammotionRTKCloudDevice
15
+
16
+
17
+ class MammotionRTKDeviceManager(AbstractDeviceManager):
18
+ """Manages an RTK device with both cloud and BLE connectivity options."""
19
+
20
+ def __init__(
21
+ self,
22
+ name: str,
23
+ iot_id: str,
24
+ cloud_client: CloudIOTGateway,
25
+ cloud_device: Device,
26
+ ble_device: BLEDevice | None = None,
27
+ mqtt: MammotionCloud | None = None,
28
+ preference: ConnectionPreference = ConnectionPreference.WIFI,
29
+ ) -> None:
30
+ """Initialize RTK device manager."""
31
+ super().__init__(name, iot_id, cloud_client, cloud_device, preference)
32
+ # Store as generic interfaces to satisfy AbstractDeviceManager contract
33
+ self._ble_device: MammotionRTKBLEDevice | None = None
34
+ self._cloud_device: MammotionRTKCloudDevice | None = None
35
+ self.name = name
36
+ self.iot_id = iot_id
37
+ self.cloud_client = cloud_client
38
+ self._device: Device = cloud_device
39
+ self.mammotion_http = cloud_client.mammotion_http
40
+ self.preference = preference
41
+
42
+ # Initialize RTK state
43
+ self._rtk_state = RTKDevice(
44
+ name=name,
45
+ iot_id=iot_id,
46
+ product_key=cloud_device.product_key,
47
+ )
48
+
49
+ # Add connection types if provided
50
+ if ble_device:
51
+ self.add_ble(ble_device)
52
+ if mqtt:
53
+ self.add_cloud(mqtt)
54
+
55
+ @property
56
+ def state(self) -> RTKDevice:
57
+ """Return the RTK device state."""
58
+ return self._rtk_state
59
+
60
+ @state.setter
61
+ def state(self, value: RTKDevice) -> None:
62
+ """Set the RTK device state."""
63
+ self._rtk_state = value
64
+
65
+ @property
66
+ def ble(self) -> MammotionRTKBLEDevice | None:
67
+ """Return BLE device interface."""
68
+ return self._ble_device
69
+
70
+ @property
71
+ def cloud(self) -> MammotionRTKCloudDevice | None:
72
+ """Return cloud device interface."""
73
+ return self._cloud_device
74
+
75
+ def has_queued_commands(self) -> bool:
76
+ """Check if there are queued commands."""
77
+ if self.cloud and self.preference == ConnectionPreference.WIFI:
78
+ return not self.cloud.mqtt.command_queue.empty()
79
+ elif self.ble:
80
+ return not self.ble.command_queue.empty()
81
+ return False
82
+
83
+ def add_ble(self, ble_device: BLEDevice) -> MammotionRTKBLEDevice:
84
+ """Add BLE device."""
85
+ self._ble_device = MammotionRTKBLEDevice(
86
+ cloud_device=self._device, rtk_state=self._rtk_state, device=ble_device
87
+ )
88
+ return self._ble_device
89
+
90
+ @override
91
+ def add_cloud(self, mqtt: MammotionCloud) -> MammotionRTKCloudDevice:
92
+ """Add cloud device."""
93
+ self._cloud_device = MammotionRTKCloudDevice(mqtt, cloud_device=self._device, rtk_state=self._rtk_state)
94
+ return self._cloud_device
95
+
96
+ def replace_cloud(self, cloud_device: MammotionRTKCloudDevice) -> None:
97
+ """Replace cloud device."""
98
+ self._cloud_device = cloud_device
99
+
100
+ def remove_cloud(self) -> None:
101
+ """Remove cloud device."""
102
+ self._cloud_device = None
103
+
104
+ def replace_ble(self, ble_device: MammotionRTKBLEDevice) -> None:
105
+ """Replace BLE device."""
106
+ self._ble_device = ble_device
107
+
108
+ def remove_ble(self) -> None:
109
+ """Remove BLE device."""
110
+ self._ble_device = None
111
+
112
+ def replace_mqtt(self, mqtt: MammotionCloud) -> None:
113
+ """Replace MQTT connection."""
114
+ if cloud_device := self._cloud_device:
115
+ self._cloud_device = MammotionRTKCloudDevice(
116
+ mqtt, cloud_device=cloud_device.device, rtk_state=self._rtk_state
117
+ )
118
+
119
+ def has_cloud(self) -> bool:
120
+ """Check if cloud connection is available."""
121
+ return self._cloud_device is not None
122
+
123
+ def has_ble(self) -> bool:
124
+ """Check if BLE connection is available."""
125
+ return self._ble_device is not None
@@ -0,0 +1,6 @@
1
+ """Package for MammotionMQTT."""
2
+
3
+ from .aliyun_mqtt import AliyunMQTT
4
+ from .mammotion_mqtt import MammotionMQTT
5
+
6
+ __all__ = ["AliyunMQTT", "MammotionMQTT"]