mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 14:38:15 +01:00
fix for stepid on load recipe/addstep
This commit is contained in:
parent
bc6649dff8
commit
6ac93e5212
4 changed files with 23 additions and 23 deletions
|
@ -1 +1 @@
|
|||
__version__ = "4.0.2.0.a16"
|
||||
__version__ = "4.0.2.0.a17"
|
||||
|
|
|
@ -117,15 +117,6 @@ class CBPiStep(CBPiBase):
|
|||
def __str__(self):
|
||||
return "name={} props={}, type={}".format(self.name, self.props, self.__class__.__name__)
|
||||
|
||||
#class CBPiFermentationStep(CBPiStep):
|
||||
|
||||
# def __init__(self, cbpi, fermenter, step, props, on_done) -> None:
|
||||
# self.fermenter = fermenter
|
||||
# id = step.get("id")
|
||||
# name=step.get("name")
|
||||
# self.step=step
|
||||
# super().__init__(cbpi, id, name, props, on_done)
|
||||
|
||||
class CBPiFermentationStep(CBPiBase):
|
||||
|
||||
def __init__(self, cbpi, fermenter, step, props, on_done) -> None:
|
||||
|
|
|
@ -238,16 +238,16 @@ class FermentationController:
|
|||
with open(self.path, "w") as file:
|
||||
json.dump(data, file, indent=4, sort_keys=True)
|
||||
|
||||
async def create_step(self, id, item):
|
||||
def create_step(self, id, item):
|
||||
try:
|
||||
stepid = shortuuid.uuid()
|
||||
props = item.get("props")
|
||||
item['id'] = stepid
|
||||
status = StepState("I")
|
||||
type = item.get("type")
|
||||
name = item.get("name")
|
||||
endtime = item.get("endtime", 0)
|
||||
props = Props(item.get("props"))
|
||||
fermenter = self._find_by_id(id)
|
||||
|
||||
try:
|
||||
type_cfg = self.steptypes.get(type)
|
||||
clazz = type_cfg.get("class")
|
||||
|
@ -255,13 +255,8 @@ class FermentationController:
|
|||
except Exception as e:
|
||||
logging.warning("Failed to create step instance %s - %s" % (id, e))
|
||||
instance = None
|
||||
step = FermenterStep(id=stepid, name=name, fermenter=fermenter, props=props, type=type, status=status, instance=instance)
|
||||
step = FermenterStep(id=stepid, name=name, fermenter=fermenter, props=props, type=type, status=status, endtime=endtime, instance=instance)
|
||||
|
||||
|
||||
|
||||
fermenter.steps.append(step)
|
||||
self.save()
|
||||
self.push_update("fermenterstepupdate")
|
||||
return step
|
||||
except Exception as e:
|
||||
self.logger.error(e)
|
||||
|
@ -546,18 +541,32 @@ class FermentationController:
|
|||
except:
|
||||
pass
|
||||
fermenter = self._find_by_id(fermenterid)
|
||||
|
||||
def add_runtime_data(item):
|
||||
item["status"] = "I"
|
||||
item["endtime"] = 0
|
||||
item["id"] = shortuuid.uuid()
|
||||
item["props"]["Sensor"] = fermenter.sensor
|
||||
|
||||
list(map(lambda item: add_runtime_data(item), data.get("steps")))
|
||||
fermenter.description = data['basic']['desc']
|
||||
if name is not None:
|
||||
fermenter.brewname = name
|
||||
else:
|
||||
fermenter.brewname = data['basic']['name']
|
||||
fermenter.steps=[]
|
||||
await self.update(fermenter)
|
||||
fermenter.steps=[]
|
||||
for item in data.get("steps"):
|
||||
await self.create_step(fermenterid, item)
|
||||
fermenter.steps.append(self.create_step(fermenterid, item))
|
||||
|
||||
self.save()
|
||||
self.push_update("fermenterstepupdate")
|
||||
|
||||
async def add_step(self, fermenterid, newstep):
|
||||
fermenter = self._find_by_id(fermenterid)
|
||||
step = self.create_step(fermenterid, newstep)
|
||||
fermenter.steps.append(step)
|
||||
self.save()
|
||||
self.push_update("fermenterstepupdate")
|
||||
return step
|
||||
|
|
@ -313,8 +313,8 @@ class FermentationHttpEndpoints():
|
|||
|
||||
data = await request.json()
|
||||
fermenterid= request.match_info['id']
|
||||
newstep = {"name": data.get("name"), "props": data.get("props", {}), "type": data.get("type")}
|
||||
response_data = await self.controller.create_step(fermenterid,newstep)
|
||||
newstep = {"name": data.get("name"), "props": data.get("props", {}), "endtime": 0, "type": data.get("type")}
|
||||
response_data = await self.controller.add_step(fermenterid,newstep)
|
||||
return web.json_response(data=response_data.to_dict())
|
||||
|
||||
@request_mapping(path="/{fermenterid}/{stepid}", method="PUT", auth_required=False)
|
||||
|
|
Loading…
Reference in a new issue