pymammotion 0.2.2__tar.gz → 0.2.4__tar.gz

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 (116) hide show
  1. {pymammotion-0.2.2 → pymammotion-0.2.4}/PKG-INFO +1 -1
  2. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/cloud_gateway.py +4 -0
  3. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/devices/mammotion.py +132 -63
  4. {pymammotion-0.2.2 → pymammotion-0.2.4}/pyproject.toml +6 -2
  5. {pymammotion-0.2.2 → pymammotion-0.2.4}/LICENSE +0 -0
  6. {pymammotion-0.2.2 → pymammotion-0.2.4}/README.md +0 -0
  7. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/__init__.py +0 -0
  8. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/__init__.py +0 -0
  9. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/cloud_service.py +0 -0
  10. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/dataclass/aep_response.py +0 -0
  11. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/dataclass/connect_response.py +0 -0
  12. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/dataclass/dev_by_account_response.py +0 -0
  13. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/dataclass/login_by_oauth_response.py +0 -0
  14. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/dataclass/regions_response.py +0 -0
  15. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/dataclass/session_by_authcode_response.py +0 -0
  16. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/aliyun/tmp_constant.py +0 -0
  17. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/__init__.py +0 -0
  18. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/ble.py +0 -0
  19. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/ble_message.py +0 -0
  20. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/const.py +0 -0
  21. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/data/__init__.py +0 -0
  22. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/data/convert.py +0 -0
  23. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/data/framectrldata.py +0 -0
  24. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/bluetooth/data/notifydata.py +0 -0
  25. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/const.py +0 -0
  26. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/__init__.py +0 -0
  27. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/__init__.py +0 -0
  28. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/account.py +0 -0
  29. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/device.py +0 -0
  30. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/device_config.py +0 -0
  31. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/enums.py +0 -0
  32. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/excute_boarder_params.py +0 -0
  33. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/execute_boarder.py +0 -0
  34. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/generate_route_information.py +0 -0
  35. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/hash_list.py +0 -0
  36. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/location.py +0 -0
  37. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/mowing_modes.py +0 -0
  38. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/plan.py +0 -0
  39. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/rapid_state.py +0 -0
  40. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/region_data.py +0 -0
  41. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/model/report_info.py +0 -0
  42. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/mqtt/__init__.py +0 -0
  43. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/mqtt/event.py +0 -0
  44. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/mqtt/properties.py +0 -0
  45. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/mqtt/status.py +0 -0
  46. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/data/state_manager.py +0 -0
  47. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/event/__init__.py +0 -0
  48. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/event/event.py +0 -0
  49. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/http/_init_.py +0 -0
  50. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/http/http.py +0 -0
  51. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/__init__.py +0 -0
  52. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/__init__.py +0 -0
  53. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/abstract_message.py +0 -0
  54. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/mammotion_command.py +0 -0
  55. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/__init__.py +0 -0
  56. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/driver.py +0 -0
  57. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/media.py +0 -0
  58. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/navigation.py +0 -0
  59. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/network.py +0 -0
  60. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/ota.py +0 -0
  61. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/system.py +0 -0
  62. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/commands/messages/video.py +0 -0
  63. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/control/__init__.py +0 -0
  64. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/control/joystick.py +0 -0
  65. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mammotion/devices/__init__.py +0 -0
  66. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mqtt/__init__.py +0 -0
  67. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/mqtt/mammotion_mqtt.py +0 -0
  68. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/__init__.py +0 -0
  69. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/basestation.proto +0 -0
  70. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/basestation.py +0 -0
  71. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/basestation_pb2.py +0 -0
  72. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/basestation_pb2.pyi +0 -0
  73. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/common.proto +0 -0
  74. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/common.py +0 -0
  75. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/common_pb2.py +0 -0
  76. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/common_pb2.pyi +0 -0
  77. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/dev_net.proto +0 -0
  78. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/dev_net.py +0 -0
  79. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/dev_net_pb2.py +0 -0
  80. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/dev_net_pb2.pyi +0 -0
  81. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_msg.proto +0 -0
  82. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_msg.py +0 -0
  83. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_msg_pb2.py +0 -0
  84. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_msg_pb2.pyi +0 -0
  85. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_mul.proto +0 -0
  86. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_mul.py +0 -0
  87. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_mul_pb2.py +0 -0
  88. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/luba_mul_pb2.pyi +0 -0
  89. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_driver.proto +0 -0
  90. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_driver.py +0 -0
  91. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_driver_pb2.py +0 -0
  92. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_driver_pb2.pyi +0 -0
  93. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_nav.proto +0 -0
  94. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_nav.py +0 -0
  95. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_nav_pb2.py +0 -0
  96. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_nav_pb2.pyi +0 -0
  97. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_ota.proto +0 -0
  98. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_ota.py +0 -0
  99. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_ota_pb2.py +0 -0
  100. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_ota_pb2.pyi +0 -0
  101. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_pept.proto +0 -0
  102. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_pept.py +0 -0
  103. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_pept_pb2.py +0 -0
  104. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_pept_pb2.pyi +0 -0
  105. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_sys.proto +0 -0
  106. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_sys.py +0 -0
  107. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_sys_pb2.py +0 -0
  108. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/proto/mctrl_sys_pb2.pyi +0 -0
  109. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/py.typed +0 -0
  110. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/constant/__init__.py +0 -0
  111. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/constant/device_constant.py +0 -0
  112. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/datatype_converter.py +0 -0
  113. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/device_type.py +0 -0
  114. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/map.py +0 -0
  115. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/periodic.py +0 -0
  116. {pymammotion-0.2.2 → pymammotion-0.2.4}/pymammotion/utility/rocker_util.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymammotion
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary:
5
5
  License: GNU-3.0
6
6
  Author: Michael Arthur
@@ -527,3 +527,7 @@ class CloudIOTGateway:
527
527
  return ""
528
528
 
529
529
  return message_id
530
+
531
+ @property
532
+ def listing_dev_by_account_response(self):
533
+ return self._listing_dev_by_account_response
@@ -26,6 +26,7 @@ from bleak_retry_connector import (
26
26
  )
27
27
 
28
28
  from pymammotion.aliyun.cloud_gateway import CloudIOTGateway
29
+ from pymammotion.aliyun.dataclass.dev_by_account_response import Device
29
30
  from pymammotion.bluetooth import BleMessage
30
31
  from pymammotion.const import MAMMOTION_DOMAIN
31
32
  from pymammotion.data.model import RegionData
@@ -33,7 +34,7 @@ from pymammotion.data.model.account import Credentials
33
34
  from pymammotion.data.model.device import MowingDevice
34
35
  from pymammotion.data.mqtt.event import ThingEventMessage
35
36
  from pymammotion.data.state_manager import StateManager
36
- from pymammotion.http.http import MammotionHTTP, connect_http
37
+ from pymammotion.http.http import connect_http
37
38
  from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
38
39
  from pymammotion.mqtt import MammotionMQTT
39
40
  from pymammotion.proto.luba_msg import LubaMsg
@@ -125,23 +126,82 @@ class ConnectionPreference(Enum):
125
126
  WIFI = 1
126
127
  BLUETOOTH = 2
127
128
 
129
+ class MammotionMixedDeviceManager:
130
+ _ble_device: MammotionBaseBLEDevice | None = None
131
+ _cloud_device: MammotionBaseCloudDevice | None = None
132
+ _mowing_state: MowingDevice = MowingDevice()
133
+
134
+ def __init__(self, name: str, cloud_device: Device | None = None,
135
+ ble_device: BLEDevice | None = None, mqtt: MammotionMQTT | None = None) -> None:
136
+ self.name = name
137
+ self.add_ble(ble_device)
138
+ self.add_cloud(cloud_device, mqtt)
139
+
140
+ def mower_state(self):
141
+ return self._mowing_state
142
+
143
+ def ble(self) -> MammotionBaseBLEDevice | None:
144
+ return self._ble_device
145
+
146
+ def cloud(self) -> MammotionBaseCloudDevice | None:
147
+ return self._cloud_device
148
+
149
+ def add_ble(self, ble_device: BLEDevice) -> None:
150
+ if ble_device is not None:
151
+ self._ble_device = MammotionBaseBLEDevice(self._mowing_state, ble_device)
152
+
153
+ def add_cloud(self, cloud_device: Device | None = None, mqtt: MammotionMQTT | None = None) -> None:
154
+ if cloud_device is not None:
155
+ self._cloud_device = MammotionBaseCloudDevice(
156
+ mqtt_client=mqtt,
157
+ cloud_device=cloud_device,
158
+ mowing_state=self._mowing_state)
159
+
160
+ def replace_cloud(self, cloud_device:MammotionBaseCloudDevice) -> None:
161
+ self._cloud_device = cloud_device
162
+
163
+ def replace_ble(self, ble_device:MammotionBaseBLEDevice) -> None:
164
+ self._ble_device = ble_device
165
+
166
+ def has_cloud(self) -> bool:
167
+ return self._cloud_device is not None
168
+
169
+ def has_ble(self) -> bool:
170
+ return self._ble_device is not None
171
+
172
+
173
+ class MammotionDevices:
128
174
 
129
- class MammotionDevice:
175
+ devices: dict[str, MammotionMixedDeviceManager] = {}
176
+
177
+ def add_device(self, mammotion_device: MammotionMixedDeviceManager) -> None:
178
+ exists: MammotionMixedDeviceManager | None = self.devices.get(mammotion_device.name)
179
+ if not exists:
180
+ self.devices[mammotion_device.name] = mammotion_device
181
+ if mammotion_device.has_cloud():
182
+ exists.replace_cloud(mammotion_device.cloud())
183
+ if mammotion_device.has_ble():
184
+ exists.replace_ble(mammotion_device.ble())
185
+
186
+ def get_device(self, mammotion_device_name: str) -> MammotionMixedDeviceManager:
187
+ return self.devices.get(mammotion_device_name)
188
+
189
+ class Mammotion:
130
190
  """Represents a Mammotion device."""
131
191
 
132
- _ble_device: MammotionBaseBLEDevice | None = None
133
- _cloud_device: MammotionBaseCloudDevice | None = None
134
- _devices_list = []
192
+ devices = MammotionDevices()
135
193
 
136
194
  def __init__(
137
195
  self,
138
196
  ble_device: BLEDevice,
139
197
  cloud_credentials: Credentials | None = None,
140
- preference: ConnectionPreference = ConnectionPreference.EITHER,
198
+ preference: ConnectionPreference = ConnectionPreference.BLUETOOTH,
141
199
  ) -> None:
142
200
  """Initialize MammotionDevice."""
143
201
  if ble_device:
144
- self._ble_device = MammotionBaseBLEDevice(ble_device)
202
+ self.devices.add_device(MammotionMixedDeviceManager(name=ble_device.name, ble_device=ble_device))
203
+
204
+ if preference:
145
205
  self._preference = preference
146
206
 
147
207
  if cloud_credentials:
@@ -160,16 +220,10 @@ class MammotionDevice:
160
220
  _mammotion_mqtt._cloud_client = cloud_client
161
221
  _mammotion_mqtt.connect_async()
162
222
 
163
- self._devices_list = []
164
- for device in cloud_client._listing_dev_by_account_response.data.data:
165
- if (device.deviceName.startswith(("Luba-", "Yuka-"))):
166
- dev = MammotionBaseCloudDevice(
167
- mqtt_client=_mammotion_mqtt,
168
- iot_id=device.iotId,
169
- device_name=device.deviceName,
170
- nick_name=device.nickName
171
- )
172
- self._devices_list.append(dev)
223
+ for device in cloud_client.listing_dev_by_account_response.data.data:
224
+ if device.deviceName.startswith(("Luba-", "Yuka-")):
225
+ self.devices.add_device(MammotionMixedDeviceManager(name=device.deviceName, cloud_device=device, mqtt=_mammotion_mqtt))
226
+
173
227
 
174
228
  @staticmethod
175
229
  async def login(account: str, password: str) -> CloudIOTGateway:
@@ -189,36 +243,51 @@ class MammotionDevice:
189
243
  cloud_client.list_binding_by_account()
190
244
  return cloud_client
191
245
 
246
+ def get_device_by_name(self, name: str) -> MammotionMixedDeviceManager:
247
+ return self.devices.get_device(name)
192
248
 
193
- async def send_command(self, key: str):
249
+ async def send_command(self, name: str, key: str):
194
250
  """Send a command to the device."""
195
- if self._preference is ConnectionPreference.BLUETOOTH:
196
- return await self._ble_device.command(key)
197
- if self._preference is ConnectionPreference.WIFI:
198
- return await self._cloud_device.command(key)
199
- # TODO work with both with EITHER
200
-
201
- async def send_command_with_args(self, key, kwargs):
251
+ device = self.get_device_by_name(name)
252
+ if device:
253
+ if self._preference is ConnectionPreference.BLUETOOTH:
254
+ return await device.ble().command(key)
255
+ if self._preference is ConnectionPreference.WIFI:
256
+ return await device.cloud().command(key)
257
+ # TODO work with both with EITHER
258
+
259
+ async def send_command_with_args(self,name: str, key: str, kwargs):
202
260
  """Send a command with args to the device."""
203
- if self._preference is ConnectionPreference.BLUETOOTH:
204
- return await self._ble_device.command(key, **kwargs)
205
- if self._preference is ConnectionPreference.WIFI:
206
- return await self._cloud_device.command(key, **kwargs)
207
- # TODO work with both with EITHER
208
-
209
- async def start_sync(self, retry: int):
210
- if self._preference is ConnectionPreference.BLUETOOTH:
211
- return await self._ble_device.start_sync(retry)
212
- if self._preference is ConnectionPreference.WIFI:
213
- return await self._cloud_device.start_sync(retry)
214
- # TODO work with both with EITHER
215
-
216
- async def start_map_sync(self):
217
- if self._preference is ConnectionPreference.BLUETOOTH:
218
- return await self._ble_device.start_map_sync()
219
- if self._preference is ConnectionPreference.WIFI:
220
- return await self._cloud_device.start_map_sync()
221
- # TODO work with both with EITHER
261
+ device = self.get_device_by_name(name)
262
+ if device:
263
+ if self._preference is ConnectionPreference.BLUETOOTH:
264
+ return await device.ble().command(key, **kwargs)
265
+ if self._preference is ConnectionPreference.WIFI:
266
+ return await device.cloud().command(key, **kwargs)
267
+ # TODO work with both with EITHER
268
+
269
+ async def start_sync(self,name:str, retry: int):
270
+ device = self.get_device_by_name(name)
271
+ if device:
272
+ if self._preference is ConnectionPreference.BLUETOOTH:
273
+ return await device.ble().start_sync(retry)
274
+ if self._preference is ConnectionPreference.WIFI:
275
+ return await device.cloud().start_sync(retry)
276
+ # TODO work with both with EITHER
277
+
278
+ async def start_map_sync(self, name:str):
279
+ device = self.get_device_by_name(name)
280
+ if device:
281
+ if self._preference is ConnectionPreference.BLUETOOTH:
282
+ return await device.ble().start_map_sync()
283
+ if self._preference is ConnectionPreference.WIFI:
284
+ return await device.cloud().start_map_sync()
285
+ # TODO work with both with EITHER
286
+
287
+ def mower(self, name: str):
288
+ device = self.get_device_by_name(name)
289
+ if device:
290
+ return device.mower_state
222
291
 
223
292
  def has_field(message: betterproto.Message) -> bool:
224
293
  """Check if the message has any fields serialized on wire."""
@@ -228,15 +297,15 @@ def has_field(message: betterproto.Message) -> bool:
228
297
  class MammotionBaseDevice:
229
298
  """Base class for Mammotion devices."""
230
299
 
231
- _luba_msg: MowingDevice
300
+ _mower: MowingDevice
232
301
  _state_manager: StateManager
233
302
 
234
- def __init__(self) -> None:
303
+ def __init__(self, device: MowingDevice) -> None:
235
304
  """Initialize MammotionBaseDevice."""
236
305
  self.loop = asyncio.get_event_loop()
237
306
  self._raw_data = LubaMsg().to_dict(casing=betterproto.Casing.SNAKE)
238
- self._luba_msg = MowingDevice()
239
- self._state_manager = StateManager(self._luba_msg)
307
+ self._mower = device
308
+ self._state_manager = StateManager(self._mower)
240
309
 
241
310
  self._state_manager.gethash_ack_callback.add_subscribers(self.datahash_response)
242
311
  self._state_manager.get_commondata_ack_callback.add_subscribers(self.commdata_response)
@@ -259,7 +328,7 @@ class MammotionBaseDevice:
259
328
  if total_frame == current_frame:
260
329
  # get next in hash ack list
261
330
 
262
- data_hash = find_next_integer(self.luba_msg.nav.toapp_gethash_ack.data_couple, common_data.hash)
331
+ data_hash = find_next_integer(self._mower.nav.toapp_gethash_ack.data_couple, common_data.hash)
263
332
  if data_hash is None:
264
333
  return
265
334
  result_hash = 0
@@ -296,7 +365,7 @@ class MammotionBaseDevice:
296
365
  case "ota":
297
366
  self._update_ota_data(tmp_msg)
298
367
 
299
- self._luba_msg.update_raw(self._raw_data)
368
+ self._mower.update_raw(self._raw_data)
300
369
 
301
370
  def _update_nav_data(self, tmp_msg):
302
371
  """Update navigation data."""
@@ -370,9 +439,9 @@ class MammotionBaseDevice:
370
439
  return self._raw_data
371
440
 
372
441
  @property
373
- def luba_msg(self) -> MowingDevice:
442
+ def mower(self) -> MowingDevice:
374
443
  """Get the LubaMsg of the device."""
375
- return self._luba_msg
444
+ return self._mower
376
445
 
377
446
  @abstractmethod
378
447
  async def _send_command(self, key: str, retry: int | None = None) -> bytes | None:
@@ -405,7 +474,7 @@ class MammotionBaseDevice:
405
474
  await self._send_command_with_args("get_hash_response", total_frame=1, current_frame=1)
406
475
 
407
476
  await self._send_command_with_args(
408
- "get_area_name_list", device_id=self.luba_msg.device.net.toapp_wifi_iot_status.devicename
477
+ "get_area_name_list", device_id=self._mower.device.net.toapp_wifi_iot_status.devicename
409
478
  )
410
479
 
411
480
  # sub_cmd 3 is job hashes??
@@ -421,13 +490,14 @@ class MammotionBaseDevice:
421
490
  class MammotionBaseBLEDevice(MammotionBaseDevice):
422
491
  """Base class for Mammotion BLE devices."""
423
492
 
424
- def __init__(self, device: BLEDevice, interface: int = 0, **kwargs: Any) -> None:
493
+ def __init__(self, mowing_state: MowingDevice, device: BLEDevice, interface: int = 0, **kwargs: Any) -> None:
425
494
  """Initialize MammotionBaseBLEDevice."""
426
- super().__init__()
495
+ super().__init__(mowing_state)
427
496
  self._ble_sync_task = None
428
497
  self._prev_notification = None
429
498
  self._interface = f"hci{interface}"
430
499
  self._device = device
500
+ self._mower = mowing_state
431
501
  self._client: BleakClientWithServiceCache | None = None
432
502
  self._read_char: BleakGATTCharacteristic | None = None
433
503
  self._write_char: BleakGATTCharacteristic | None = None
@@ -802,20 +872,19 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
802
872
  def __init__(
803
873
  self,
804
874
  mqtt_client: MammotionMQTT,
805
- iot_id: str,
806
- device_name: str,
807
- nick_name: str,
808
- **kwargs: Any,
875
+ cloud_device: Device,
876
+ mowing_state: MowingDevice
809
877
  ) -> None:
810
878
  """Initialize MammotionBaseCloudDevice."""
811
- super().__init__()
879
+ super().__init__(mowing_state)
812
880
  self._ble_sync_task = None
813
881
  self.is_ready = False
814
882
  self._mqtt_client = mqtt_client
815
- self.iot_id = iot_id
816
- self.nick_name = nick_name
883
+ self.iot_id = cloud_device.iotId
884
+ self.device = cloud_device
885
+ self._mower = mowing_state
817
886
  self._command_futures = {}
818
- self._commands: MammotionCommand = MammotionCommand(device_name)
887
+ self._commands: MammotionCommand = MammotionCommand(cloud_device.deviceName)
819
888
  self.currentID = ""
820
889
  self.on_ready_callback: Optional[Callable[[], None]] = None
821
890
  self._operation_lock = asyncio.Lock()
@@ -1,6 +1,10 @@
1
+ [project]
2
+ name = "pymammotion"
3
+ version = "0.2.4"
4
+
1
5
  [tool.poetry]
2
6
  name = "pymammotion"
3
- version = "0.2.2"
7
+ version = "0.2.4"
4
8
  license = "GNU-3.0"
5
9
  description = ""
6
10
  readme = "README.md"
@@ -48,7 +52,7 @@ mypy = "^1.10.0"
48
52
  pre-commit = "^3.7.1"
49
53
 
50
54
  [tool.bumpver]
51
- current_version = "0.2.2"
55
+ current_version = "0.2.4"
52
56
  version_pattern = "MAJOR.MINOR.PATCH"
53
57
  commit_message = "Bump version {old_version} -> {new_version}"
54
58
  commit = true
File without changes
File without changes