mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-10 01:17:42 +01:00
update on fermenter steps - Work In Progress
This commit is contained in:
parent
08aaad7a78
commit
286198fcd1
3 changed files with 56 additions and 12 deletions
|
@ -1 +1 @@
|
||||||
__version__ = "4.0.1.17.a3"
|
__version__ = "4.0.1.18.a4"
|
||||||
|
|
|
@ -74,7 +74,7 @@ class FermentStep:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
|
||||||
async def on_start(self):
|
async def on_start(self):
|
||||||
self.props.hello = "WOOHOo"
|
#self.props.hello = "WOOHOo"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def on_stop(self):
|
async def on_stop(self):
|
||||||
|
@ -109,13 +109,17 @@ class FermentationController:
|
||||||
destfile = os.path.join(".", 'config', "fermenter_data.json")
|
destfile = os.path.join(".", 'config', "fermenter_data.json")
|
||||||
json.dump(data,open(destfile,'w'),indent=4, sort_keys=True)
|
json.dump(data,open(destfile,'w'),indent=4, sort_keys=True)
|
||||||
|
|
||||||
def push_update(self):
|
def push_update(self, key="fermenterupdate", fermentersteps=None):
|
||||||
self.cbpi.ws.send(dict(topic=self.update_key, data=list(map(lambda item: item.to_dict(), self.data))))
|
|
||||||
#self.cbpi.push_update("cbpi/{}".format(self.update_key), list(map(lambda item: item.to_dict(), self.data)))
|
|
||||||
|
|
||||||
for item in self.data:
|
if key == self.update_key:
|
||||||
self.cbpi.push_update("cbpi/{}/{}".format(self.update_key,item.id), item.to_dict())
|
self.cbpi.ws.send(dict(topic=key, data=list(map(lambda item: item.to_dict(), self.data))))
|
||||||
pass
|
#self.cbpi.push_update("cbpi/{}".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
|
||||||
|
else:
|
||||||
|
self.cbpi.ws.send(dict(topic=key, data=fermentersteps))
|
||||||
|
|
||||||
async def shutdown(self, app=None):
|
async def shutdown(self, app=None):
|
||||||
self.save()
|
self.save()
|
||||||
|
@ -141,6 +145,7 @@ class FermentationController:
|
||||||
def _create_step(self, fermenter, item):
|
def _create_step(self, fermenter, item):
|
||||||
id = item.get("id")
|
id = item.get("id")
|
||||||
name = item.get("name")
|
name = item.get("name")
|
||||||
|
props = Props(item.get("props"))
|
||||||
status = StepState(item.get("status", "I"))
|
status = StepState(item.get("status", "I"))
|
||||||
type = item.get("type")
|
type = item.get("type")
|
||||||
|
|
||||||
|
@ -149,7 +154,7 @@ class FermentationController:
|
||||||
inst = type_cfg.get("class")()
|
inst = type_cfg.get("class")()
|
||||||
print(inst)
|
print(inst)
|
||||||
|
|
||||||
step = FermenterStep(id=id, name=name, type=type, status=status, instance=None, fermenter=fermenter)
|
step = FermenterStep(id=id, name=name, fermenter=fermenter, props=props, type=type, status=status, instance=None)
|
||||||
step.instance = FermentStep( self.cbpi, step, self._done)
|
step.instance = FermentStep( self.cbpi, step, self._done)
|
||||||
return step
|
return step
|
||||||
|
|
||||||
|
@ -213,7 +218,6 @@ class FermentationController:
|
||||||
for fermenter in steplist:
|
for fermenter in steplist:
|
||||||
if fermenterid == fermenter.get("id"):
|
if fermenterid == fermenter.get("id"):
|
||||||
fermentersteps={"id": fermenter.get("id"), "steps": fermenter.get("steps")}
|
fermentersteps={"id": fermenter.get("id"), "steps": fermenter.get("steps")}
|
||||||
logging.info(fermentersteps)
|
|
||||||
return fermentersteps
|
return fermentersteps
|
||||||
|
|
||||||
def get_fermenter_steps(self):
|
def get_fermenter_steps(self):
|
||||||
|
@ -225,7 +229,6 @@ class FermentationController:
|
||||||
for fermenter in steplist:
|
for fermenter in steplist:
|
||||||
fermenterstep={"id": fermenter.get("id"), "steps": fermenter.get("steps")}
|
fermenterstep={"id": fermenter.get("id"), "steps": fermenter.get("steps")}
|
||||||
fermentersteps.append(fermenterstep)
|
fermentersteps.append(fermenterstep)
|
||||||
logging.info(fermentersteps)
|
|
||||||
return fermentersteps
|
return fermentersteps
|
||||||
|
|
||||||
async def get(self, id: str ):
|
async def get(self, id: str ):
|
||||||
|
@ -289,6 +292,8 @@ class FermentationController:
|
||||||
|
|
||||||
item.steps.append(step)
|
item.steps.append(step)
|
||||||
self.save()
|
self.save()
|
||||||
|
fermentersteps=self.get_fermenter_steps()
|
||||||
|
self.push_update("fermenterstepupdate", fermentersteps)
|
||||||
return step
|
return step
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
@ -297,12 +302,26 @@ class FermentationController:
|
||||||
item = self._find_by_id(id)
|
item = self._find_by_id(id)
|
||||||
item.steps = list(map(lambda old: step if old.id == step.id else old, item.steps))
|
item.steps = list(map(lambda old: step if old.id == step.id else old, item.steps))
|
||||||
self.save()
|
self.save()
|
||||||
|
fermentersteps=self.get_fermenter_steps()
|
||||||
|
self.push_update("fermenterstepupdate", fermentersteps)
|
||||||
|
|
||||||
|
|
||||||
async def delete_step(self, id, stepid):
|
async def delete_step(self, id, stepid):
|
||||||
item = self._find_by_id(id)
|
item = self._find_by_id(id)
|
||||||
|
# might require later check if step is active
|
||||||
item.steps = list(filter(lambda item: item.id != stepid, item.steps))
|
item.steps = list(filter(lambda item: item.id != stepid, item.steps))
|
||||||
self.save()
|
self.save()
|
||||||
|
fermentersteps=self.get_fermenter_steps()
|
||||||
|
self.push_update("fermenterstepupdate", fermentersteps)
|
||||||
|
|
||||||
|
async def clearsteps(self, id):
|
||||||
|
item = self._find_by_id(id)
|
||||||
|
# might require later check if step is active
|
||||||
|
item.steps = []
|
||||||
|
self.save()
|
||||||
|
fermentersteps=self.get_fermenter_steps()
|
||||||
|
self.push_update("fermenterstepupdate", fermentersteps)
|
||||||
|
|
||||||
|
|
||||||
def _find_by_status(self, data, status):
|
def _find_by_status(self, data, status):
|
||||||
return next((item for item in data if item.status == status), None)
|
return next((item for item in data if item.status == status), None)
|
||||||
|
@ -412,6 +431,7 @@ class FermentationController:
|
||||||
|
|
||||||
fermenter.steps[index], fermenter.steps[index+direction] = fermenter.steps[index+direction], fermenter.steps[index]
|
fermenter.steps[index], fermenter.steps[index+direction] = fermenter.steps[index+direction], fermenter.steps[index]
|
||||||
self.save()
|
self.save()
|
||||||
|
self.push_update()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
|
|
@ -439,3 +439,27 @@ class FermentationHttpEndpoints():
|
||||||
fermenterid= request.match_info['id']
|
fermenterid= request.match_info['id']
|
||||||
response_data = self.controller.get_step_state(fermenterid)
|
response_data = self.controller.get_step_state(fermenterid)
|
||||||
return web.json_response(data=response_data)
|
return web.json_response(data=response_data)
|
||||||
|
|
||||||
|
@request_mapping(path="/{id}/clearsteps", method="POST", auth_required=False)
|
||||||
|
async def http_clear_steps(self, request):
|
||||||
|
|
||||||
|
"""
|
||||||
|
---
|
||||||
|
description: Clear all steps for Fermenter with fermenterid
|
||||||
|
tags:
|
||||||
|
- Fermenter
|
||||||
|
parameters:
|
||||||
|
- name: "id"
|
||||||
|
in: "path"
|
||||||
|
description: "Fermenter ID"
|
||||||
|
required: true
|
||||||
|
type: "integer"
|
||||||
|
format: "int64"
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: successful operation
|
||||||
|
"""
|
||||||
|
|
||||||
|
fermenterid= request.match_info['id']
|
||||||
|
await self.controller.clearsteps(fermenterid)
|
||||||
|
return web.Response(status=200)
|
Loading…
Reference in a new issue