mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 08:28:23 +01:00
added fermenterstep actions
This commit is contained in:
parent
9ed640cf6a
commit
2d481bff81
3 changed files with 56 additions and 8 deletions
|
@ -1 +1 @@
|
|||
__version__ = "4.0.1.18.a8"
|
||||
__version__ = "4.0.1.18.a9"
|
||||
|
|
|
@ -152,16 +152,11 @@ class FermentationController:
|
|||
instance = None
|
||||
|
||||
step = FermenterStep(id=id, name=name, fermenter=fermenter, props=props, type=type, status=status, instance=instance)
|
||||
#logging.info(step)
|
||||
#logging.info(step.status)
|
||||
return step
|
||||
|
||||
def _done(self, step_instance, result, fermenter):
|
||||
step_instance.step["status"] = "D"
|
||||
self.save()
|
||||
logging.info(step_instance)
|
||||
logging.info(step_instance.step)
|
||||
logging.info(fermenter)
|
||||
if result == StepResult.NEXT:
|
||||
asyncio.create_task(self.start(fermenter))
|
||||
|
||||
|
@ -211,7 +206,6 @@ class FermentationController:
|
|||
|
||||
def get_step_state(self, fermenterid=None):
|
||||
if self.data == []:
|
||||
#logging.info(self.data)
|
||||
pass
|
||||
fermentersteps=[]
|
||||
steplist=list(map(lambda x: x.to_dict(), self.data))
|
||||
|
@ -231,6 +225,15 @@ class FermentationController:
|
|||
fermentersteps.append(fermenterstep)
|
||||
return fermentersteps
|
||||
|
||||
async def find_step_by_id(self, id):
|
||||
actionstep = None
|
||||
for item in self.data:
|
||||
step = self._find_step_by_id(item.steps, id)
|
||||
if step is not None:
|
||||
actionstep=step
|
||||
return actionstep
|
||||
|
||||
|
||||
async def get(self, id: str ):
|
||||
return self._find_by_id(id)
|
||||
|
||||
|
@ -534,3 +537,11 @@ class FermentationController:
|
|||
fermentersteps=self.get_fermenter_steps()
|
||||
self.cbpi.ws.send(dict(topic=key, data=fermentersteps))
|
||||
|
||||
async def call_action(self, id, action, parameter) -> None:
|
||||
logging.info("FermenterStep Controller - call Action {} {}".format(id, action))
|
||||
try:
|
||||
item = await self.find_step_by_id(id)
|
||||
logging.info(item)
|
||||
await item.instance.__getattribute__(action)(**parameter)
|
||||
except Exception as e:
|
||||
logging.error("FermenterStep Controller - Failed to call action on {} {} {}".format(id, action, e))
|
|
@ -584,3 +584,40 @@ class FermentationHttpEndpoints():
|
|||
fermenterid= request.match_info['id']
|
||||
await self.controller.reset(fermenterid)
|
||||
return web.Response(status=200)
|
||||
|
||||
@request_mapping(path="/action/{id}", method="POST", auth_required=False)
|
||||
async def http_call_action(self, request):
|
||||
"""
|
||||
---
|
||||
description: Call action
|
||||
tags:
|
||||
- Fermenter
|
||||
parameters:
|
||||
- name: "id"
|
||||
in: "path"
|
||||
description: "FermenterStep id"
|
||||
required: true
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
- in: body
|
||||
name: body
|
||||
description: call action for fermenter Step
|
||||
required: false
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
action:
|
||||
type: string
|
||||
parameter:
|
||||
type: "array"
|
||||
items:
|
||||
type: string
|
||||
responses:
|
||||
"204":
|
||||
description: successful operation
|
||||
"""
|
||||
data = await request.json()
|
||||
|
||||
id = request.match_info['id']
|
||||
await self.controller.call_action(id,data.get("action"), data.get("parameter",[]))
|
||||
return web.Response(status=204)
|
Loading…
Reference in a new issue