mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 08:28:23 +01:00
Unification of mqtt data
-> sensor values are updated under sensordata/{sensorid} One topic for each sensor to keep data small (esp compatibility) actor, kettle, sensor, fermenter, steps are updated also for each id individually to keep packets small e.g. actorupdate/{actorid} This was proposed by Innuendo to ensure compatibility with the ESP based MQTTDevice
This commit is contained in:
parent
e43aaf4fcd
commit
51136aef88
7 changed files with 31 additions and 16 deletions
|
@ -1 +1 @@
|
|||
__version__ = "4.0.1.a4"
|
||||
__version__ = "4.0.1.a5"
|
||||
|
|
|
@ -35,7 +35,8 @@ class CBPiSensor(CBPiBase, metaclass=ABCMeta):
|
|||
def push_update(self, value):
|
||||
try:
|
||||
self.cbpi.ws.send(dict(topic="sensorstate", id=self.id, value=value))
|
||||
self.cbpi.push_update("cbpi/sensor/{}/udpate".format(self.id), dict(id=self.id, value=value), retain=True)
|
||||
self.cbpi.push_update("cbpi/sensordata/{}".format(self.id), dict(id=self.id, value=value), retain=True)
|
||||
# self.cbpi.push_update("cbpi/sensor/{}/udpate".format(self.id), dict(id=self.id, value=value), retain=True)
|
||||
except:
|
||||
logging.error("Faild to push sensor update")
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class ActorController(BasicController):
|
|||
if item.instance.state is False:
|
||||
await item.instance.on(power)
|
||||
await self.push_udpate()
|
||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict(), True)
|
||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict(), True)
|
||||
else:
|
||||
await self.set_power(id, power)
|
||||
|
||||
|
@ -34,7 +34,7 @@ class ActorController(BasicController):
|
|||
if item.instance.state is True:
|
||||
await item.instance.off()
|
||||
await self.push_udpate()
|
||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
|
||||
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,7 +43,7 @@ class ActorController(BasicController):
|
|||
item = self.find_by_id(id)
|
||||
instance = item.get("instance")
|
||||
await instance.toggle()
|
||||
self.cbpi.push_update("cbpi/actor/update", item.to_dict())
|
||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
||||
except Exception as e:
|
||||
logging.error("Failed to toggle Actor {} {}".format(id, e))
|
||||
|
||||
|
@ -59,6 +59,6 @@ class ActorController(BasicController):
|
|||
item = self.find_by_id(id)
|
||||
item.power = round(power)
|
||||
await self.push_udpate()
|
||||
self.cbpi.push_update("cbpi/actor/"+id, item.to_dict())
|
||||
self.cbpi.push_update("cbpi/actorupdate/{}".format(id), item.to_dict())
|
||||
except Exception as e:
|
||||
logging.error("Failed to update Actor {} {}".format(id, e))
|
||||
|
|
|
@ -55,7 +55,8 @@ class BasicController:
|
|||
|
||||
async def push_udpate(self):
|
||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
||||
self.cbpi.push_update("cbpi/{}/update".format(self.update_key), list(map(lambda item: item.to_dict(), self.data)))
|
||||
for item in self.data:
|
||||
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), item.to_dict())
|
||||
|
||||
def find_by_id(self, id):
|
||||
return next((item for item in self.data if item.id == id), None)
|
||||
|
|
|
@ -110,7 +110,8 @@ class FermentationController:
|
|||
|
||||
def push_update(self):
|
||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
||||
self.cbpi.push_update("cbpi/{}/update".format(self.update_key), list(map(lambda item: item.to_dict(), self.data)))
|
||||
for item in self.data:
|
||||
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), item.to_dict())
|
||||
pass
|
||||
|
||||
async def shutdown(self, app=None):
|
||||
|
|
|
@ -256,8 +256,8 @@ class StepController:
|
|||
self.cbpi.ws.send(dict(topic="mash_profile_update", data=self.get_state()))
|
||||
else:
|
||||
self.cbpi.ws.send(dict(topic="step_update", data=list(map(lambda item: item.to_dict(), self.profile))))
|
||||
|
||||
self.cbpi.push_update(topic="cbpi/stepupdate", data=list(map(lambda item: item.to_dict(), self.profile)))
|
||||
for item in self.profile:
|
||||
self.cbpi.push_update(topic="cbpi/stepupdate/{}".format(item.id), data=(item.to_dict()))
|
||||
|
||||
async def start_step(self,step):
|
||||
try:
|
||||
|
|
|
@ -46,7 +46,8 @@ class FermenterAutostart(CBPiExtension):
|
|||
Property.Number(label="HeaterOffsetOff", configurable=True, description="Offset as decimal number when the heater is switched off. Should be smaller then 'HeaterOffsetOn'. For example a value of 1 switches off the heater if the current temperature is 1 degree below the target temperature"),
|
||||
Property.Number(label="CoolerOffsetOn", configurable=True, description="Offset as decimal number when the cooler is switched on. Should be greater then 'CoolerOffsetOff'. For example a value of 2 switches on the cooler if the current temperature is 2 degrees below the target temperature"),
|
||||
Property.Number(label="CoolerOffsetOff", configurable=True, description="Offset as decimal number when the cooler is switched off. Should be smaller then 'CoolerOffsetOn'. For example a value of 1 switches off the cooler if the current temperature is 1 degree below the target temperature"),
|
||||
Property.Select(label="AutoStart", options=["Yes","No"],description="Autostart Fermenter on cbpi start")])
|
||||
Property.Select(label="AutoStart", options=["Yes","No"],description="Autostart Fermenter on cbpi start"),
|
||||
Property.Sensor(label="sensor2",description="Optional Sensor for LCDisplay(e.g. iSpindle)")])
|
||||
|
||||
class FermenterHysteresis(CBPiFermenterLogic):
|
||||
|
||||
|
@ -61,26 +62,37 @@ class FermenterHysteresis(CBPiFermenterLogic):
|
|||
self.heater = self.fermenter.heater
|
||||
self.cooler = self.fermenter.cooler
|
||||
|
||||
heater = self.cbpi.actor.find_by_id(self.heater)
|
||||
cooler = self.cbpi.actor.find_by_id(self.cooler)
|
||||
|
||||
while self.running == True:
|
||||
|
||||
sensor_value = float(self.get_sensor_value(self.fermenter.sensor).get("value"))
|
||||
target_temp = float(self.get_fermenter_target_temp(self.id))
|
||||
|
||||
try:
|
||||
heater_state = heater.instance.state
|
||||
except:
|
||||
heater_state= False
|
||||
try:
|
||||
cooler_state = cooler.instance.state
|
||||
except:
|
||||
cooler_state= False
|
||||
|
||||
if sensor_value + self.heater_offset_min <= target_temp:
|
||||
if self.heater:
|
||||
if self.heater and (heater_state == False):
|
||||
await self.actor_on(self.heater)
|
||||
|
||||
if sensor_value + self.heater_offset_max >= target_temp:
|
||||
if self.heater:
|
||||
if self.heater and (heater_state == True):
|
||||
await self.actor_off(self.heater)
|
||||
|
||||
if sensor_value >= self.cooler_offset_min + target_temp:
|
||||
if self.cooler:
|
||||
if self.cooler and (cooler_state == False):
|
||||
await self.actor_on(self.cooler)
|
||||
|
||||
if sensor_value <= self.cooler_offset_max + target_temp:
|
||||
if self.cooler:
|
||||
if self.cooler and (cooler_state == True):
|
||||
await self.actor_off(self.cooler)
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
|
Loading…
Reference in a new issue