further tests on fermentersteps

This commit is contained in:
avollkopf 2022-02-16 20:36:11 +01:00
parent 22d629c7a8
commit b8ef79d11c
4 changed files with 140 additions and 6 deletions

View file

@ -1 +1 @@
__version__ = "4.0.1.16"
__version__ = "4.0.1.17.a1"

View file

@ -180,7 +180,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))
@ -269,11 +269,12 @@ class FermentationController:
except Exception as e:
self.logger.error(e)
async def update_step(self, id, step):
async def update_step(self, id, step: FermenterStep):
item = self._find_by_id(id)
item = list(map(lambda old: item 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()
async def delete_step(self, id, stepid):
item = self._find_by_id(id)
item.steps = list(filter(lambda item: item.id != stepid, item.steps))

View file

@ -1,5 +1,5 @@
from cbpi.controller.fermentation_controller import FermentationController
from cbpi.api.dataclasses import Fermenter, Step, Props
from cbpi.api.dataclasses import Fermenter, Step, Props, FermenterStep
from aiohttp import web
from cbpi.api import *
import logging
@ -283,3 +283,135 @@ class FermentationHttpEndpoints():
data = await request.json()
await self.controller.set_target_temp(id,data.get("temp"))
return web.Response(status=204)
@request_mapping(path="/{id}/addstep", method="POST", auth_required=False)
async def http_add_step(self, request):
"""
---
description: Add Fermenterstep
tags:
- Fermenter
parameters:
- name: "id"
in: "path"
description: "Fermenter ID"
required: true
type: "integer"
format: "int64"
- in: body
name: body
description: Create a fermenterstep
required: true
schema:
type: object
responses:
"200":
description: successful operation
"""
data = await request.json()
fermenterid= request.match_info['id']
step = FermenterStep(name=data.get("name"), props=Props(data.get("props", {})), type=data.get("type"))
response_data = await self.controller.create_step(fermenterid,step)
return web.json_response(data=response_data.to_dict())
@request_mapping(path="/{fermenterid}/{stepid}", method="PUT", auth_required=False)
async def http_updatestep(self, request):
"""
---
description: Update FermenterStep
tags:
- Fermenter
parameters:
- name: "fermenterid"
in: "path"
description: "Fermenter ID"
required: true
type: "integer"
format: "int64"
- name: "stepid"
in: "path"
description: "Step ID"
required: true
type: "integer"
format: "int64"
- in: body
name: body
description: Update a Femrenterstep
required: false
schema:
type: object
responses:
"200":
description: successful operation
"""
data = await request.json()
stepid = request.match_info['stepid']
fermenterid = request.match_info['fermenterid']
step = FermenterStep(stepid, data.get("name"), None, Props(data.get("props", {})), data.get("type"))
await self.controller.update_step(fermenterid,step)
return web.Response(status=200)
@request_mapping(path="/{fermenterid}/{stepid}", method="DELETE", auth_required=False)
async def http_deletestep(self, request):
"""
---
description: Delete Fermenterstep
tags:
- Fermenter
parameters:
- name: "fermenterid"
in: "path"
description: "Fermenter ID"
required: true
type: "integer"
format: "int64"
- name: "stepid"
in: "path"
description: "Step ID"
required: true
type: "integer"
format: "int64"
responses:
"204":
description: successful operation
"""
stepid = request.match_info['stepid']
fermenterid = request.match_info['fermenterid']
await self.controller.delete_step(fermenterid,stepid)
return web.Response(status=204)
@request_mapping(path="/movestep", method="PUT", auth_required=False)
async def http_movestep(self, request):
"""
---
description: Move Fermenterstep
tags:
- Fermenter
parameters:
- in: body
name: body
description: Created an kettle
required: false
schema:
type: object
properties:
fermenterid:
type: string
stepid:
type: string
direction:
type: "integer"
format: "int64"
responses:
"204":
description: successful operation
"""
data = await request.json()
await self.controller.move_step(data["fermenterid"],data["stepid"], data["direction"])
return web.Response(status=204)

View file

@ -1,3 +1,4 @@
import re
from aiohttp import web
from aiohttp import streamer
from cbpi.job.aiohttp import get_scheduler_from_app
@ -7,7 +8,7 @@ from cbpi.utils import json_dumps
from cbpi import __version__
import pathlib
import os
import json
from cbpi.controller.system_controller import SystemController
class SystemHttpEndpoints: