diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 3d61dfe..0ac9cc3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -15,6 +15,6 @@ RUN pip3 install --no-cache-dir -r /workspace/requirements.txt # Install current version of cbpi-ui RUN mkdir /opt/downloads \ - && curl https://github.com/craftbeerpi/craftbeerpi4-ui/archive/main.zip -L -o /opt/downloads/cbpi-ui.zip \ + && curl https://github.com/craftbeerpi/craftbeerpi4-ui/archive/development.zip -L -o /opt/downloads/cbpi-ui.zip \ && pip3 install --no-cache-dir /opt/downloads/cbpi-ui.zip \ && rm -rf /opt/downloads \ No newline at end of file diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 337aa2e..cadc596 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1,3 +1,3 @@ -__version__ = "4.0.5.a1" +__version__ = "4.0.5.a2" __codename__ = "Spring Break" diff --git a/cbpi/extension/FermenterHysteresis/__init__.py b/cbpi/extension/FermenterHysteresis/__init__.py index 5be707c..a384d96 100644 --- a/cbpi/extension/FermenterHysteresis/__init__.py +++ b/cbpi/extension/FermenterHysteresis/__init__.py @@ -100,7 +100,7 @@ class FermenterHysteresis(CBPiFermenterLogic): except asyncio.CancelledError as e: pass except Exception as e: - logging.error("CustomLogic Error {}".format(e)) + logging.error("Fermenter Hysteresis Error {}".format(e)) finally: self.running = False if self.heater: @@ -109,6 +109,103 @@ class FermenterHysteresis(CBPiFermenterLogic): await self.actor_off(self.cooler) +@parameters([Property.Number(label="HeaterOffsetOn", configurable=True, description="Offset as decimal number when the heater is switched on. Should be greater then 'HeaterOffsetOff'. For example a value of 2 switches on the heater if the current temperature is 2 degrees below the target temperature"), + 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.Number(label="SpundingOffsetOpen", configurable=True, description="Offset above target pressure as decimal number when the valve is opened"), + 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 FermenterSpundingHysteresis(CBPiFermenterLogic): + # subroutine that controls pressure + async def pressure_control(self): + self.fermenter = self.get_fermenter(self.id) + self.valve = self.fermenter.valve + self.spunding_offset=float(self.props.get("SpundingOffsetOpen",0)) + if self.valve and self.fermenter.pressure_sensor: + valve = self.cbpi.actor.find_by_id(self.valve) + + await self.actor_off(self.valve) + logging.info("Closing Spunding Valve") + + while self.running: + target_pressure=float(self.fermenter.target_pressure) + current_pressure = float(self.get_sensor_value(self.fermenter.pressure_sensor).get("value")) + logging.info(f'Target: {target_pressure} | Current: {current_pressure}') + if current_pressure >= (target_pressure + self.spunding_offset): + while current_pressure >= target_pressure: + await self.actor_on(self.valve) + await asyncio.sleep(1) + await self.actor_off(self.valve) + current_pressure = float(self.get_sensor_value(self.fermenter.pressure_sensor).get("value")) + logging.info("Value higher than target: Spunding loop is running") + + await asyncio.sleep(1) + else: + logging.info("No valve or pressure sensor defined") + + async def run(self): + try: + self.heater_offset_min = float(self.props.get("HeaterOffsetOn", 0)) + self.heater_offset_max = float(self.props.get("HeaterOffsetOff", 0)) + self.cooler_offset_min = float(self.props.get("CoolerOffsetOn", 0)) + self.cooler_offset_max = float(self.props.get("CoolerOffsetOff", 0)) + + self.fermenter = self.get_fermenter(self.id) + 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) + + pressure_controller = asyncio.create_task(self.pressure_control()) + + await pressure_controller + + 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 and (heater_state == False): + await self.actor_on(self.heater) + + if sensor_value + self.heater_offset_max >= target_temp: + 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 and (cooler_state == False): + await self.actor_on(self.cooler) + + if sensor_value <= self.cooler_offset_max + target_temp: + if self.cooler and (cooler_state == True): + await self.actor_off(self.cooler) + + await asyncio.sleep(1) + + except asyncio.CancelledError as e: + pass + except Exception as e: + logging.error("Fermenter Spunding Hysteresis Error {}".format(e)) + finally: + self.running = False + if self.heater: + await self.actor_off(self.heater) + if self.cooler: + await self.actor_off(self.cooler) def setup(cbpi): @@ -119,7 +216,7 @@ def setup(cbpi): :param cbpi: the cbpi core :return: ''' - + cbpi.plugin.register("Fermenter Spunding Hysteresis", FermenterSpundingHysteresis) cbpi.plugin.register("Fermenter Hysteresis", FermenterHysteresis) cbpi.plugin.register("Fermenter Autostart", FermenterAutostart)