added fermenterstep actions

This commit is contained in:
avollkopf 2022-02-23 07:12:51 +01:00
parent 9ed640cf6a
commit 2d481bff81
3 changed files with 56 additions and 8 deletions

View file

@ -1 +1 @@
__version__ = "4.0.1.18.a8" __version__ = "4.0.1.18.a9"

View file

@ -152,16 +152,11 @@ class FermentationController:
instance = None instance = None
step = FermenterStep(id=id, name=name, fermenter=fermenter, props=props, type=type, status=status, instance=instance) 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 return step
def _done(self, step_instance, result, fermenter): def _done(self, step_instance, result, fermenter):
step_instance.step["status"] = "D" step_instance.step["status"] = "D"
self.save() self.save()
logging.info(step_instance)
logging.info(step_instance.step)
logging.info(fermenter)
if result == StepResult.NEXT: if result == StepResult.NEXT:
asyncio.create_task(self.start(fermenter)) asyncio.create_task(self.start(fermenter))
@ -211,7 +206,6 @@ class FermentationController:
def get_step_state(self, fermenterid=None): def get_step_state(self, fermenterid=None):
if self.data == []: if self.data == []:
#logging.info(self.data)
pass pass
fermentersteps=[] fermentersteps=[]
steplist=list(map(lambda x: x.to_dict(), self.data)) steplist=list(map(lambda x: x.to_dict(), self.data))
@ -231,6 +225,15 @@ class FermentationController:
fermentersteps.append(fermenterstep) fermentersteps.append(fermenterstep)
return fermentersteps 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 ): async def get(self, id: str ):
return self._find_by_id(id) return self._find_by_id(id)
@ -534,3 +537,11 @@ class FermentationController:
fermentersteps=self.get_fermenter_steps() fermentersteps=self.get_fermenter_steps()
self.cbpi.ws.send(dict(topic=key, data=fermentersteps)) 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))

View file

@ -584,3 +584,40 @@ class FermentationHttpEndpoints():
fermenterid= request.match_info['id'] fermenterid= request.match_info['id']
await self.controller.reset(fermenterid) await self.controller.reset(fermenterid)
return web.Response(status=200) 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)