pymammotion 0.2.85__py3-none-any.whl → 0.2.87__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.
@@ -66,4 +66,7 @@ class DataEvent:
66
66
  self.on_data_event += obj_method
67
67
 
68
68
  def remove_subscribers(self, obj_method) -> None:
69
- self.on_data_event -= obj_method
69
+ try:
70
+ self.on_data_event -= obj_method
71
+ except ValueError:
72
+ """Subscription object no longer there."""
@@ -33,14 +33,11 @@ def find_next_integer(lst: list[int], current_hash: int) -> int | None:
33
33
  class MammotionBaseDevice:
34
34
  """Base class for Mammotion devices."""
35
35
 
36
- _state_manager: StateManager
37
- _cloud_device: Device | None = None
38
-
39
- def __init__(self, device: MowingDevice, cloud_device: Device | None = None) -> None:
36
+ def __init__(self, state_manager: StateManager, cloud_device: Device | None = None) -> None:
40
37
  """Initialize MammotionBaseDevice."""
41
38
  self.loop = asyncio.get_event_loop()
42
39
  self._raw_data = LubaMsg().to_dict(casing=betterproto.Casing.SNAKE)
43
- self._state_manager = StateManager(device)
40
+ self._state_manager = state_manager
44
41
  self._state_manager.gethash_ack_callback = self.datahash_response
45
42
  self._state_manager.get_commondata_ack_callback = self.commdata_response
46
43
  self._notify_future: asyncio.Future[bytes] | None = None
@@ -13,6 +13,7 @@ from pymammotion.aliyun.cloud_gateway import CloudIOTGateway
13
13
  from pymammotion.aliyun.model.dev_by_account_response import Device
14
14
  from pymammotion.data.model.account import Credentials
15
15
  from pymammotion.data.model.device import MowingDevice
16
+ from pymammotion.data.state_manager import StateManager
16
17
  from pymammotion.http.http import connect_http
17
18
  from pymammotion.mammotion.devices.mammotion_bluetooth import MammotionBaseBLEDevice
18
19
  from pymammotion.mammotion.devices.mammotion_cloud import MammotionBaseCloudDevice, MammotionCloud
@@ -32,8 +33,6 @@ class ConnectionPreference(Enum):
32
33
 
33
34
 
34
35
  class MammotionMixedDeviceManager:
35
- _ble_device: MammotionBaseBLEDevice | None = None
36
- _cloud_device: MammotionBaseCloudDevice | None = None
37
36
  preference: ConnectionPreference
38
37
 
39
38
  def __init__(
@@ -45,22 +44,20 @@ class MammotionMixedDeviceManager:
45
44
  preference: ConnectionPreference = ConnectionPreference.BLUETOOTH,
46
45
  ) -> None:
47
46
  self.name = name
48
- self._mower_state = MowingDevice()
47
+ self._ble_device: MammotionBaseBLEDevice | None = None
48
+ self._cloud_device: MammotionBaseCloudDevice | None = None
49
49
  self.add_ble(ble_device)
50
50
  self.add_cloud(cloud_device, mqtt)
51
+ self._state_manager = StateManager(MowingDevice())
51
52
  self.preference = preference
52
53
 
53
54
  @property
54
55
  def mower_state(self):
55
- return self._mower_state
56
+ return self._state_manager.get_device()
56
57
 
57
58
  @mower_state.setter
58
59
  def mower_state(self, value: MowingDevice) -> None:
59
- if self._cloud_device:
60
- self._cloud_device.state_manager.set_device(value)
61
- if self._ble_device:
62
- self._ble_device.state_manager.set_device(value)
63
- self._mower_state = value
60
+ self._state_manager.set_device(value)
64
61
 
65
62
  def ble(self) -> MammotionBaseBLEDevice | None:
66
63
  return self._ble_device
@@ -76,12 +73,12 @@ class MammotionMixedDeviceManager:
76
73
 
77
74
  def add_ble(self, ble_device: BLEDevice) -> None:
78
75
  if ble_device is not None:
79
- self._ble_device = MammotionBaseBLEDevice(self.mower_state, ble_device)
76
+ self._ble_device = MammotionBaseBLEDevice(state_manager=self._state_manager, ble_device=ble_device)
80
77
 
81
78
  def add_cloud(self, cloud_device: Device | None = None, mqtt: MammotionCloud | None = None) -> None:
82
79
  if cloud_device is not None:
83
80
  self._cloud_device = MammotionBaseCloudDevice(
84
- mqtt, cloud_device=cloud_device, mowing_state=self.mower_state
81
+ mqtt, cloud_device=cloud_device, state_manager=self._state_manager
85
82
  )
86
83
 
87
84
  def replace_cloud(self, cloud_device: MammotionBaseCloudDevice) -> None:
@@ -15,6 +15,7 @@ from bleak_retry_connector import (
15
15
 
16
16
  from pymammotion.bluetooth import BleMessage
17
17
  from pymammotion.data.model.device import MowingDevice
18
+ from pymammotion.data.state_manager import StateManager
18
19
  from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
19
20
  from pymammotion.mammotion.devices.base import MammotionBaseDevice
20
21
  from pymammotion.proto import has_field
@@ -69,9 +70,9 @@ async def _handle_retry(fut: asyncio.Future[None], func, command: bytes) -> None
69
70
  class MammotionBaseBLEDevice(MammotionBaseDevice):
70
71
  """Base class for Mammotion BLE devices."""
71
72
 
72
- def __init__(self, mowing_state: MowingDevice, device: BLEDevice, interface: int = 0, **kwargs: Any) -> None:
73
+ def __init__(self, state_manager: StateManager, device: BLEDevice, interface: int = 0, **kwargs: Any) -> None:
73
74
  """Initialize MammotionBaseBLEDevice."""
74
- super().__init__(mowing_state)
75
+ super().__init__(state_manager)
75
76
  self._disconnect_strategy = True
76
77
  self._ble_sync_task = None
77
78
  self._prev_notification = None
@@ -14,6 +14,7 @@ from pymammotion.aliyun.model.dev_by_account_response import Device
14
14
  from pymammotion.data.model.device import MowingDevice
15
15
  from pymammotion.data.mqtt.event import ThingEventMessage
16
16
  from pymammotion.data.mqtt.properties import ThingPropertiesMessage
17
+ from pymammotion.data.state_manager import StateManager
17
18
  from pymammotion.event.event import DataEvent
18
19
  from pymammotion.mammotion.commands.mammotion_command import MammotionCommand
19
20
  from pymammotion.mammotion.devices.base import MammotionBaseDevice
@@ -150,9 +151,9 @@ class MammotionCloud:
150
151
  class MammotionBaseCloudDevice(MammotionBaseDevice):
151
152
  """Base class for Mammotion Cloud devices."""
152
153
 
153
- def __init__(self, mqtt: MammotionCloud, cloud_device: Device, mowing_state: MowingDevice) -> None:
154
+ def __init__(self, mqtt: MammotionCloud, cloud_device: Device, state_manager: StateManager) -> None:
154
155
  """Initialize MammotionBaseCloudDevice."""
155
- super().__init__(mowing_state, cloud_device)
156
+ super().__init__(state_manager, cloud_device)
156
157
  self._ble_sync_task: TimerHandle | None = None
157
158
  self.stopped = False
158
159
  self.on_ready_callback: Optional[Callable[[], Awaitable[None]]] = None
@@ -173,6 +174,15 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
173
174
  if self._mqtt.is_ready:
174
175
  self.run_periodic_sync_task()
175
176
 
177
+ def __del__(self):
178
+ self._mqtt.on_ready_event.remove_subscribers(self.on_ready)
179
+ self._mqtt.on_disconnected_event.remove_subscribers(self.on_disconnect)
180
+ self._mqtt.on_connected_event.remove_subscribers(self.on_connect)
181
+ self._mqtt.mqtt_message_event.remove_subscribers(self._parse_message_for_device)
182
+ if self._ble_sync_task:
183
+ self._ble_sync_task.cancel()
184
+
185
+
176
186
  async def on_ready(self) -> None:
177
187
  """Callback for when MQTT is subscribed to events."""
178
188
  if self.stopped:
@@ -197,7 +207,6 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
197
207
  """Stop all tasks and disconnect."""
198
208
  if self._ble_sync_task:
199
209
  self._ble_sync_task.cancel()
200
- self._mqtt.on_ready_event.remove_subscribers(self.on_ready)
201
210
  self.stopped = True
202
211
 
203
212
  async def start(self) -> None:
@@ -205,7 +214,6 @@ class MammotionBaseCloudDevice(MammotionBaseDevice):
205
214
  if self._ble_sync_task is None or self._ble_sync_task.cancelled():
206
215
  await self.run_periodic_sync_task()
207
216
  self.stopped = False
208
- self._mqtt.on_ready_event.add_subscribers(self.on_ready)
209
217
  if not self.mqtt.is_connected():
210
218
  self.mqtt.connect_async()
211
219
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pymammotion
3
- Version: 0.2.85
3
+ Version: 0.2.87
4
4
  Summary:
5
5
  License: GNU-3.0
6
6
  Author: Michael Arthur
@@ -42,7 +42,7 @@ pymammotion/data/mqtt/properties.py,sha256=kvphcjrDuJHuX8Az98-wKeFv_rSmu2Fz9YKLG
42
42
  pymammotion/data/mqtt/status.py,sha256=zqnlo-MzejEQZszl0i0Wucoc3E76x6UtI9JLxoBnu54,1067
43
43
  pymammotion/data/state_manager.py,sha256=vtBT28-5DY58hJMi_kqOUKnOq6rJ4fx1zX8yU7N96A8,5357
44
44
  pymammotion/event/__init__.py,sha256=mgATR6vPHACNQ-0zH5fi7NdzeTCDV1CZyaWPmtUusi8,115
45
- pymammotion/event/event.py,sha256=UzYnxV5DfvMDK3E06UvSzvzuBbaXOOUwO6xYt_zn9To,2034
45
+ pymammotion/event/event.py,sha256=m7gDAxVcgQAWQBe7AZd3w59eMf9mlcEv27eRT-zz2c0,2133
46
46
  pymammotion/http/_init_.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  pymammotion/http/http.py,sha256=9TnVah-R8nkjlb6oCMk78IZ0Y-2iAcMyIdjcQ54GEPk,3562
48
48
  pymammotion/http/model/http.py,sha256=_hHqe9IfKDukUYKQDrZb_Tt_9rd5BNN1WKsaGIjsexM,1876
@@ -61,10 +61,10 @@ pymammotion/mammotion/commands/messages/video.py,sha256=ne1YSuQChaDFfmHgMO5Jc9_O
61
61
  pymammotion/mammotion/control/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  pymammotion/mammotion/control/joystick.py,sha256=QfBVxM_gxpWsZAGO90whtgxCI2tIZ3TTad9wHIPsU9s,5640
63
63
  pymammotion/mammotion/devices/__init__.py,sha256=f2qQFPgLGmV85W2hSlMUh5BYuht9o_Ar_JEAAMD4fsE,102
64
- pymammotion/mammotion/devices/base.py,sha256=F_L5aDtY6rgRkk7Q4CwilLenTANW6cBe9zIU3a9HRmA,10020
65
- pymammotion/mammotion/devices/mammotion.py,sha256=hSO184o1q4ftfLPx9froFPIXk428wGg8Ayw160W3z7c,12482
66
- pymammotion/mammotion/devices/mammotion_bluetooth.py,sha256=KjcIta1VcJ8eNJvPFeOtwxV2jl3nrk7PldMmPv_Caqw,18939
67
- pymammotion/mammotion/devices/mammotion_cloud.py,sha256=ghNR1av4GJjrHPFWWTCnhNCA6MDmZq0lR7-ZfqweE7I,12337
64
+ pymammotion/mammotion/devices/base.py,sha256=WRRDJsIftlvJ56C7uDbwx2nvb60MORHMGSBWbwlN9g8,9946
65
+ pymammotion/mammotion/devices/mammotion.py,sha256=nVSaHORBC28DWlEpND79AZIZgNYYkBCXL0F1MWWo99E,12447
66
+ pymammotion/mammotion/devices/mammotion_bluetooth.py,sha256=BqvYJhuK-fFx-0cuoi0zPFL3Hg2ZwSNsPlE_I2DTXos,18997
67
+ pymammotion/mammotion/devices/mammotion_cloud.py,sha256=W50O7m6IRwsVoE5PZS9dWTGtH9Xh37J5Abb4honzNf4,12671
68
68
  pymammotion/mqtt/__init__.py,sha256=Ocs5e-HLJvTuDpVXyECEsWIvwsUaxzj7lZ9mSYutNDY,105
69
69
  pymammotion/mqtt/mammotion_future.py,sha256=_OWqKOlUGl2yT1xOsXFQYpGd-1zQ63OxqXgy7KRQgYc,710
70
70
  pymammotion/mqtt/mammotion_mqtt.py,sha256=LaySave_hf0gU3crUTLqzpdQtxIwK8vu5DM8F8fbU2Y,8748
@@ -119,7 +119,7 @@ pymammotion/utility/map.py,sha256=GYscVMg2cX3IPlNpCBNHDW0S55yS1WGRf1iHnNZ7TfQ,22
119
119
  pymammotion/utility/movement.py,sha256=N75oAoAgFydqoaOedYIxGUHmuTCtPzAOtb-d_29tpfI,615
120
120
  pymammotion/utility/periodic.py,sha256=MbeSb9cfhxzYmdT_RiE0dZe3H9IfbQW_zSqhmSX2RUc,3321
121
121
  pymammotion/utility/rocker_util.py,sha256=6tX7sS87qoQC_tsxbx3NLL-HgS08wtzXiZkhDiz7uo0,7179
122
- pymammotion-0.2.85.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
123
- pymammotion-0.2.85.dist-info/METADATA,sha256=HJQ0Tzx-L-_zoBerxpjSCkTo42-dFPBfkIrK81y7FQg,3896
124
- pymammotion-0.2.85.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
125
- pymammotion-0.2.85.dist-info/RECORD,,
122
+ pymammotion-0.2.87.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
123
+ pymammotion-0.2.87.dist-info/METADATA,sha256=a6_Lu9jJkXtrO_gwtKliY7hjIAnxO3F6_rbqcfyY3dY,3896
124
+ pymammotion-0.2.87.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
125
+ pymammotion-0.2.87.dist-info/RECORD,,