mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-12-22 13:34:55 +01:00
Added dummy pressure sensor for testing of spunding functionality
This commit is contained in:
parent
d1f656f509
commit
4d95017842
4 changed files with 48 additions and 7 deletions
|
@ -1,3 +1,3 @@
|
|||
__version__ = "4.0.5.a6"
|
||||
__version__ = "4.0.5.a7"
|
||||
__codename__ = "Spring Break"
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ class FermentationController:
|
|||
|
||||
|
||||
def _find_by_id(self, id):
|
||||
return next((item for item in self.data if item.id == id), None)
|
||||
return next((item for item in self.data if item.id == id), None)
|
||||
|
||||
async def get_all(self):
|
||||
return list(map(lambda x: x.to_dict(), self.data))
|
||||
|
|
|
@ -289,6 +289,7 @@ class CraftBeerPi:
|
|||
self._setup_http_index()
|
||||
self.plugin.load_plugins()
|
||||
self.plugin.load_plugins_from_evn()
|
||||
await self.fermenter.init()
|
||||
await self.sensor.init()
|
||||
await self.step.init()
|
||||
|
||||
|
@ -296,8 +297,8 @@ class CraftBeerPi:
|
|||
await self.kettle.init()
|
||||
await self.call_initializer(self.app)
|
||||
await self.dashboard.init()
|
||||
await self.fermenter.init()
|
||||
|
||||
|
||||
|
||||
self._swagger_setup()
|
||||
|
||||
level = logging.INFO
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import asyncio
|
||||
import random
|
||||
|
||||
from cbpi.api import parameters, CBPiSensor
|
||||
|
||||
import logging
|
||||
from cbpi.api import *
|
||||
from cbpi.api.base import CBPiBase
|
||||
from cbpi.api.dataclasses import Kettle, Props, Fermenter
|
||||
|
||||
@parameters([])
|
||||
class CustomSensor(CBPiSensor):
|
||||
|
@ -23,6 +24,44 @@ class CustomSensor(CBPiSensor):
|
|||
def get_state(self):
|
||||
return dict(value=self.value)
|
||||
|
||||
@parameters([Property.Number(label="Pressure", configurable=True, description="Start Pressure"),
|
||||
Property.Number(label="PressureIncrease", configurable=True, description="Pressure increase per hour"),
|
||||
Property.Number(label="PressureDecrease", configurable=True, description="Pressure decrease per second on openm valve"),
|
||||
Property.Fermenter(label="Fermenter",description="Fermenter")])
|
||||
class DummyPressure(CBPiSensor):
|
||||
|
||||
def __init__(self, cbpi, id, props):
|
||||
super(DummyPressure, self).__init__(cbpi, id, props)
|
||||
self.value = float(self.props.get("Pressure",0))
|
||||
fermenter=self.props.get("Fermenter",None)
|
||||
self.fermenter=self.get_fermenter(fermenter)
|
||||
self.valve=self.fermenter.valve
|
||||
|
||||
async def run(self):
|
||||
self.uprate=float(self.props.get("PressureIncrease",0))/3600
|
||||
self.decrease=float(self.props.get("PressureDecrease",0))
|
||||
logging.info(self.uprate)
|
||||
logging.info(self.decrease)
|
||||
|
||||
while self.running:
|
||||
valve_state=self.get_actor_state(self.valve)
|
||||
fermenter_instance=self.fermenter.instance
|
||||
if fermenter_instance:
|
||||
fermenter_state=fermenter_instance.state
|
||||
else:
|
||||
fermenter_state = False
|
||||
if valve_state == False and fermenter_state:
|
||||
self.value = self.value + self.uprate
|
||||
elif valve_state and fermenter_state:
|
||||
self.value=self.value-self.decrease
|
||||
|
||||
self.log_data(self.value)
|
||||
|
||||
self.push_update(round(self.value,2))
|
||||
await asyncio.sleep(1)
|
||||
|
||||
def get_state(self):
|
||||
return dict(value=self.value)
|
||||
|
||||
def setup(cbpi):
|
||||
'''
|
||||
|
@ -33,3 +72,4 @@ def setup(cbpi):
|
|||
:return:
|
||||
'''
|
||||
cbpi.plugin.register("CustomSensor", CustomSensor)
|
||||
cbpi.plugin.register("DummyPressure", DummyPressure)
|
||||
|
|
Loading…
Reference in a new issue