Reduction of duplicated mqtt actor messages

This commit is contained in:
avollkopf 2022-02-03 17:00:12 +01:00
parent ed141f8788
commit 0bf2b64c3e
3 changed files with 9 additions and 6 deletions

View file

@ -1 +1 @@
__version__ = "4.0.1.9"
__version__ = "4.0.1.10"

View file

@ -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))

View file

@ -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: