From 0bf2b64c3edfa2a7db319deea0159091185bfdd5 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Thu, 3 Feb 2022 17:00:12 +0100 Subject: [PATCH] Reduction of duplicated mqtt actor messages --- cbpi/__init__.py | 2 +- cbpi/controller/actor_controller.py | 11 +++++++---- cbpi/controller/satellite_controller.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 1f11a12..763e1e5 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1 +1 @@ -__version__ = "4.0.1.9" +__version__ = "4.0.1.10" diff --git a/cbpi/controller/actor_controller.py b/cbpi/controller/actor_controller.py index edb559d..f31abeb 100644 --- a/cbpi/controller/actor_controller.py +++ b/cbpi/controller/actor_controller.py @@ -9,7 +9,6 @@ class ActorController(BasicController): self.update_key = "actorupdate" async def on(self, id, power=None): -# logging.info("Controller_power: {}".format(power)) try: item = self.find_by_id(id) if power is None: @@ -20,7 +19,8 @@ class ActorController(BasicController): power = 100 if item.instance.state is False: await item.instance.on(power) - await self.push_udpate() + #await self.push_udpate() + self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data)))) self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict(), True) else: await self.set_power(id, power) @@ -33,7 +33,8 @@ class ActorController(BasicController): item = self.find_by_id(id) if item.instance.state is True: await item.instance.off() - await self.push_udpate() + #await self.push_udpate() + self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data)))) self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict()) except Exception as e: logging.error("Failed to switch on Actor {} {}".format(id, e), True) @@ -43,6 +44,7 @@ class ActorController(BasicController): item = self.find_by_id(id) instance = item.get("instance") await instance.toggle() + self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data)))) self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict()) except Exception as e: logging.error("Failed to toggle Actor {} {}".format(id, e)) @@ -58,7 +60,8 @@ class ActorController(BasicController): try: item = self.find_by_id(id) item.power = round(power) - await self.push_udpate() + #await self.push_udpate() + self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data)))) self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict()) except Exception as e: logging.error("Failed to update Actor {} {}".format(id, e)) diff --git a/cbpi/controller/satellite_controller.py b/cbpi/controller/satellite_controller.py index 4629ac8..3fbcd0d 100644 --- a/cbpi/controller/satellite_controller.py +++ b/cbpi/controller/satellite_controller.py @@ -63,7 +63,7 @@ class SatelliteController: if power < 0: power = 0 await self.cbpi.actor.set_power(topic_key[2],power) - await self.cbpi.actor.actor_update(topic_key[2],power) + #await self.cbpi.actor.actor_update(topic_key[2],power) except: self.logger.warning("Failed to set actor power via mqtt. No valid power in message") except: