From 7d840c4eb30ee4406f24f9b6db4a355eca932cba Mon Sep 17 00:00:00 2001 From: Michael Arthur Date: Thu, 24 Oct 2024 13:37:41 +1300 Subject: [PATCH] stop calling stop when device goes offline --- pymammotion/mammotion/devices/mammotion_bluetooth.py | 3 ++- pymammotion/mammotion/devices/mammotion_cloud.py | 5 +++-- pyproject.toml | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pymammotion/mammotion/devices/mammotion_bluetooth.py b/pymammotion/mammotion/devices/mammotion_bluetooth.py index 75ad7aa..b5365da 100644 --- a/pymammotion/mammotion/devices/mammotion_bluetooth.py +++ b/pymammotion/mammotion/devices/mammotion_bluetooth.py @@ -118,7 +118,8 @@ def schedule_ble_sync(self) -> None: async def stop(self) -> None: """Stop all tasks and disconnect.""" - self._ble_sync_task.cancel() + if self._ble_sync_task: + self._ble_sync_task.cancel() if self._client is not None: await self._client.disconnect() diff --git a/pymammotion/mammotion/devices/mammotion_cloud.py b/pymammotion/mammotion/devices/mammotion_cloud.py index 64bcaf0..04d3ed5 100644 --- a/pymammotion/mammotion/devices/mammotion_cloud.py +++ b/pymammotion/mammotion/devices/mammotion_cloud.py @@ -181,7 +181,7 @@ async def on_ready(self) -> None: if self.on_ready_callback: await self.on_ready_callback() except DeviceOfflineException: - await self.stop() + _LOGGER.debug("Device is offline") async def on_disconnect(self) -> None: if self._ble_sync_task: @@ -201,7 +201,8 @@ async def start(self) -> None: await self.run_periodic_sync_task() self.stopped = False self._mqtt.on_ready_event.add_subscribers(self.on_ready) - self.mqtt.connect_async() + if not self.mqtt.is_connected(): + self.mqtt.connect_async() async def _ble_sync(self) -> None: command_bytes = self._commands.send_todev_ble_sync(3) diff --git a/pyproject.toml b/pyproject.toml index ef72dda..5aaa827 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [project] name = "pymammotion" -version = "0.2.76" +version = "0.2.78" [tool.poetry] name = "pymammotion" -version = "0.2.76" +version = "0.2.78" license = "GNU-3.0" description = "" readme = "README.md" @@ -61,7 +61,7 @@ mypy = "^1.11.2" autotyping = "^24.3.0" [tool.bumpver] -current_version = "0.2.76" +current_version = "0.2.78" version_pattern = "MAJOR.MINOR.PATCH" commit_message = "Bump version {old_version} -> {new_version}" commit = true