mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-12-22 21:44:57 +01:00
Bug fix for first startup w/o fermenter
This commit is contained in:
parent
d7c1b64493
commit
751b3dcad9
4 changed files with 56 additions and 44 deletions
|
@ -1 +1 @@
|
||||||
__version__ = "4.0.1.a1"
|
__version__ = "4.0.1.a2"
|
||||||
|
|
|
@ -88,7 +88,7 @@ class FermentationController:
|
||||||
self.logger = logging.getLogger(__name__)
|
self.logger = logging.getLogger(__name__)
|
||||||
self.path = os.path.join(".", 'config', "fermenter_data.json")
|
self.path = os.path.join(".", 'config', "fermenter_data.json")
|
||||||
self._loop = asyncio.get_event_loop()
|
self._loop = asyncio.get_event_loop()
|
||||||
self.data = {}
|
self.data = []
|
||||||
self.types = {}
|
self.types = {}
|
||||||
self.cbpi.app.on_cleanup.append(self.shutdown)
|
self.cbpi.app.on_cleanup.append(self.shutdown)
|
||||||
|
|
||||||
|
@ -125,16 +125,14 @@ class FermentationController:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
|
||||||
async def load(self):
|
async def load(self):
|
||||||
if os.path.exists(self.path) is False:
|
# if os.path.exists(self.path) is False:
|
||||||
with open(self.path, "w") as file:
|
# with open(self.path, "w") as file:
|
||||||
json.dump(dict(basic={}, steps=[]), file, indent=4, sort_keys=True)
|
# json.dump(dict(basic={}, steps=[]), file, indent=4, sort_keys=True)
|
||||||
with open(self.path) as json_file:
|
with open(self.path) as json_file:
|
||||||
d = json.load(json_file)
|
data = json.load(json_file)
|
||||||
self.data = list(map(lambda item: self._create(item), d))
|
|
||||||
|
|
||||||
#for item in self.data:
|
for i in data["data"]:
|
||||||
# logging.info("{} Starting ".format(item.name))
|
self.data.append(self._create(i))
|
||||||
# await self.start(item.id)
|
|
||||||
|
|
||||||
def _create_step(self, fermenter, item):
|
def _create_step(self, fermenter, item):
|
||||||
id = item.get("id")
|
id = item.get("id")
|
||||||
|
@ -159,6 +157,7 @@ class FermentationController:
|
||||||
asyncio.create_task(self.start(step_instance.step.fermenter.id))
|
asyncio.create_task(self.start(step_instance.step.fermenter.id))
|
||||||
|
|
||||||
def _create(self, data):
|
def _create(self, data):
|
||||||
|
try:
|
||||||
id = data.get("id")
|
id = data.get("id")
|
||||||
name = data.get("name")
|
name = data.get("name")
|
||||||
sensor = data.get("sensor")
|
sensor = data.get("sensor")
|
||||||
|
@ -173,8 +172,10 @@ class FermentationController:
|
||||||
self.push_update()
|
self.push_update()
|
||||||
#self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
#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)))
|
#self.cbpi.push_update("cbpi/{}/update".format(self.update_key), list(map(lambda item: item.to_dict(), self.data)))
|
||||||
|
|
||||||
return fermenter
|
return fermenter
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def _find_by_id(self, id):
|
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)
|
||||||
|
@ -191,6 +192,9 @@ class FermentationController:
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
# logging.info("{} Get State".format(self.name))
|
# logging.info("{} Get State".format(self.name))
|
||||||
|
if self.data == []:
|
||||||
|
logging.info(self.data)
|
||||||
|
|
||||||
return {"data": list(map(lambda x: x.to_dict(), self.data)), "types":self.get_types()}
|
return {"data": list(map(lambda x: x.to_dict(), self.data)), "types":self.get_types()}
|
||||||
|
|
||||||
async def get(self, id: str ):
|
async def get(self, id: str ):
|
||||||
|
|
|
@ -18,10 +18,10 @@ class FermenterAutostart(CBPiExtension):
|
||||||
self._task = asyncio.create_task(self.run())
|
self._task = asyncio.create_task(self.run())
|
||||||
self.controller : FermentationController = cbpi.fermenter
|
self.controller : FermentationController = cbpi.fermenter
|
||||||
|
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
logging.info("Starting Fermenter Autorun")
|
logging.info("Starting Fermenter Autorun")
|
||||||
#get all kettles
|
#get all kettles
|
||||||
|
try:
|
||||||
self.fermenter = self.controller.get_state()
|
self.fermenter = self.controller.get_state()
|
||||||
for id in self.fermenter['data']:
|
for id in self.fermenter['data']:
|
||||||
try:
|
try:
|
||||||
|
@ -38,6 +38,8 @@ class FermenterAutostart(CBPiExtension):
|
||||||
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
|
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@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"),
|
@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"),
|
||||||
|
|
|
@ -27,6 +27,12 @@ class SystemHttpEndpoints:
|
||||||
"200":
|
"200":
|
||||||
description: successful operation
|
description: successful operation
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
|
fermenter=self.cbpi.fermenter.get_state()
|
||||||
|
logging.info(fermenter)
|
||||||
|
except:
|
||||||
|
logging.info("!!!!!!!!!!!!!!!!!!!!!!!!!Error get fermenter state!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||||
|
|
||||||
return web.json_response(data=dict(
|
return web.json_response(data=dict(
|
||||||
actor=self.cbpi.actor.get_state(),
|
actor=self.cbpi.actor.get_state(),
|
||||||
fermenter=self.cbpi.fermenter.get_state(),
|
fermenter=self.cbpi.fermenter.get_state(),
|
||||||
|
|
Loading…
Reference in a new issue