From 3768a77dfe17ebc13652e71b08011dcb8378dee8 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Sat, 25 Mar 2023 19:15:26 +0100 Subject: [PATCH] added soome additional info on cancelled task --- cbpi/__init__.py | 2 +- cbpi/controller/satellite_controller.py | 8 ++++++-- cbpi/extension/mqtt_sensor/__init__.py | 10 +++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 9b0b24d..18a652d 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.1.7.a12" +__version__ = "4.1.7.a13" __codename__ = "Groundhog Day" diff --git a/cbpi/controller/satellite_controller.py b/cbpi/controller/satellite_controller.py index 47779dd..7060401 100644 --- a/cbpi/controller/satellite_controller.py +++ b/cbpi/controller/satellite_controller.py @@ -153,6 +153,7 @@ class SatelliteController: return task async def _subcribe(self, topic, method): + self.error=False while True: try: if self.client._connected.done(): @@ -164,10 +165,13 @@ class SatelliteController: except asyncio.CancelledError: # Cancel self.logger.warning("Sub Cancelled") - break + self.error=True except MqttError as e: self.logger.error("Sub MQTT Exception: {}".format(e)) except Exception as e: self.logger.error("Sub Exception: {}".format(e)) # wait before try to resubscribe - await asyncio.sleep(5) + if self.error == True: + break + else: + await asyncio.sleep(5) diff --git a/cbpi/extension/mqtt_sensor/__init__.py b/cbpi/extension/mqtt_sensor/__init__.py index d7c78d3..c9dce95 100644 --- a/cbpi/extension/mqtt_sensor/__init__.py +++ b/cbpi/extension/mqtt_sensor/__init__.py @@ -127,15 +127,15 @@ class MQTTSensor(CBPiSensor): async def on_stop(self): if not self.mqtt_task.done(): - logging.warning("Task not done -> cancelling") - self.mqtt_task.cancel() + logging.info("Task not done -> cancelling") + was_cancelled = self.mqtt_task.cancel() try: - logging.warning("trying to call cancelled task") + logging.info("Trying to call cancelled task") await self.mqtt_task except asyncio.CancelledError: - logging.warning("Task has been Cancelled") + logging.info("Task has been Cancelled") pass - + logging.info("Task cancelled: {}".format(was_cancelled)) def setup(cbpi): '''