change of mqtt payloads for fermenterupdate and fermenterstepupdate

This commit is contained in:
avollkopf 2024-02-22 19:45:06 +01:00
parent ef67caaa68
commit 28f0ca9779
4 changed files with 26 additions and 5 deletions

View file

@ -1,3 +1,3 @@
__version__ = "4.3.2.a7" __version__ = "4.3.2.a8"
__codename__ = "Winter Storm" __codename__ = "Winter Storm"

View file

@ -525,13 +525,19 @@ class FermentationController:
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)
def remove_key(self,d, key):
r = dict(d)
del r[key]
return r
def push_update(self, key="fermenterupdate"): def push_update(self, key="fermenterupdate"):
if key == self.update_key: if key == self.update_key:
self.cbpi.ws.send(dict(topic=key, data=list(map(lambda item: item.to_dict(), self.data)))) self.cbpi.ws.send(dict(topic=key, data=list(map(lambda item: item.to_dict(), self.data))))
for item in self.data: for item in self.data:
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), item.to_dict()) fermenters=self.remove_key(item.to_dict(),"steps")
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), fermenters)
pass pass
else: else:
fermentersteps=self.get_fermenter_steps() fermentersteps=self.get_fermenter_steps()
@ -542,6 +548,9 @@ class FermentationController:
for step in fermenter['steps']: for step in fermenter['steps']:
if step['status'] == 'A': if step['status'] == 'A':
self.cbpi.push_update("cbpi/{}/{}/{}".format(key,fermenter['id'],step['id']), step) self.cbpi.push_update("cbpi/{}/{}/{}".format(key,fermenter['id'],step['id']), step)
else:
self.cbpi.push_update("cbpi/{}/{}/{}".format(key,fermenter['id'],step['id']), "")
async def call_action(self, id, action, parameter) -> None: async def call_action(self, id, action, parameter) -> None:
logging.info("FermenterStep Controller - call Action {} {}".format(id, action)) logging.info("FermenterStep Controller - call Action {} {}".format(id, action))

View file

@ -35,6 +35,11 @@ class SatelliteController:
] ]
self.tasks = set() self.tasks = set()
def remove_key(self,d, key):
r = dict(d)
del r[key]
return r
async def init(self): async def init(self):
#not sure if required like done in the old routine #not sure if required like done in the old routine
@ -132,7 +137,8 @@ class SatelliteController:
try: try:
self.fermenter=self.fermentercontroller.get_state() self.fermenter=self.fermentercontroller.get_state()
for item in self.fermenter['data']: for item in self.fermenter['data']:
self.cbpi.push_update("cbpi/{}/{}".format("fermenterupdate",item['id']), item) item_new=self.remove_key(item,"steps")
self.cbpi.push_update("cbpi/{}/{}".format("fermenterupdate",item['id']), item_new)
except Exception as e: except Exception as e:
self.logger.warning("Failed to send fermenterupdate via mqtt: {}".format(e)) self.logger.warning("Failed to send fermenterupdate via mqtt: {}".format(e))

View file

@ -37,6 +37,11 @@ class MQTTUtil(CBPiExtension):
self.push_update() self.push_update()
await asyncio.sleep(self.mqttupdate) await asyncio.sleep(self.mqttupdate)
def remove_key(self,d, key):
r = dict(d)
del r[key]
return r
def push_update(self): def push_update(self):
# try: # try:
# self.actor=self.actorcontroller.get_state() # self.actor=self.actorcontroller.get_state()
@ -62,7 +67,8 @@ class MQTTUtil(CBPiExtension):
try: try:
self.fermenter=self.fermentationcontroller.get_state() self.fermenter=self.fermentationcontroller.get_state()
for item in self.fermenter['data']: for item in self.fermenter['data']:
self.cbpi.push_update("cbpi/{}/{}".format("fermenterupdate",item['id']), item) item_new=self.remove_key(item,"steps")
self.cbpi.push_update("cbpi/{}/{}".format("fermenterupdate",item['id']), item_new)
except Exception as e: except Exception as e:
logging.error(e) logging.error(e)
pass pass