mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-25 08:28:23 +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):
|
def __str__(self):
|
||||||
return "name={} props={}, type={}".format(self.name, self.props, self.__class__.__name__)
|
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):
|
class CBPiFermentationStep(CBPiBase):
|
||||||
|
|
||||||
def __init__(self, cbpi, fermenter, step, props, on_done) -> None:
|
def __init__(self, cbpi, fermenter, step, props, on_done) -> None:
|
||||||
|
|
|
@ -238,16 +238,16 @@ class FermentationController:
|
||||||
with open(self.path, "w") as file:
|
with open(self.path, "w") as file:
|
||||||
json.dump(data, file, indent=4, sort_keys=True)
|
json.dump(data, file, indent=4, sort_keys=True)
|
||||||
|
|
||||||
async def create_step(self, id, item):
|
def create_step(self, id, item):
|
||||||
try:
|
try:
|
||||||
stepid = shortuuid.uuid()
|
stepid = shortuuid.uuid()
|
||||||
props = item.get("props")
|
item['id'] = stepid
|
||||||
status = StepState("I")
|
status = StepState("I")
|
||||||
type = item.get("type")
|
type = item.get("type")
|
||||||
name = item.get("name")
|
name = item.get("name")
|
||||||
|
endtime = item.get("endtime", 0)
|
||||||
props = Props(item.get("props"))
|
props = Props(item.get("props"))
|
||||||
fermenter = self._find_by_id(id)
|
fermenter = self._find_by_id(id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
type_cfg = self.steptypes.get(type)
|
type_cfg = self.steptypes.get(type)
|
||||||
clazz = type_cfg.get("class")
|
clazz = type_cfg.get("class")
|
||||||
|
@ -255,13 +255,8 @@ class FermentationController:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warning("Failed to create step instance %s - %s" % (id, e))
|
logging.warning("Failed to create step instance %s - %s" % (id, e))
|
||||||
instance = None
|
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
|
return step
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(e)
|
self.logger.error(e)
|
||||||
|
@ -546,18 +541,32 @@ class FermentationController:
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
fermenter = self._find_by_id(fermenterid)
|
fermenter = self._find_by_id(fermenterid)
|
||||||
|
|
||||||
def add_runtime_data(item):
|
def add_runtime_data(item):
|
||||||
item["status"] = "I"
|
item["status"] = "I"
|
||||||
item["endtime"] = 0
|
item["endtime"] = 0
|
||||||
item["id"] = shortuuid.uuid()
|
item["id"] = shortuuid.uuid()
|
||||||
item["props"]["Sensor"] = fermenter.sensor
|
item["props"]["Sensor"] = fermenter.sensor
|
||||||
|
|
||||||
list(map(lambda item: add_runtime_data(item), data.get("steps")))
|
list(map(lambda item: add_runtime_data(item), data.get("steps")))
|
||||||
fermenter.description = data['basic']['desc']
|
fermenter.description = data['basic']['desc']
|
||||||
if name is not None:
|
if name is not None:
|
||||||
fermenter.brewname = name
|
fermenter.brewname = name
|
||||||
else:
|
else:
|
||||||
fermenter.brewname = data['basic']['name']
|
fermenter.brewname = data['basic']['name']
|
||||||
fermenter.steps=[]
|
|
||||||
await self.update(fermenter)
|
await self.update(fermenter)
|
||||||
|
fermenter.steps=[]
|
||||||
for item in data.get("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()
|
data = await request.json()
|
||||||
fermenterid= request.match_info['id']
|
fermenterid= request.match_info['id']
|
||||||
newstep = {"name": data.get("name"), "props": data.get("props", {}), "type": data.get("type")}
|
newstep = {"name": data.get("name"), "props": data.get("props", {}), "endtime": 0, "type": data.get("type")}
|
||||||
response_data = await self.controller.create_step(fermenterid,newstep)
|
response_data = await self.controller.add_step(fermenterid,newstep)
|
||||||
return web.json_response(data=response_data.to_dict())
|
return web.json_response(data=response_data.to_dict())
|
||||||
|
|
||||||
@request_mapping(path="/{fermenterid}/{stepid}", method="PUT", auth_required=False)
|
@request_mapping(path="/{fermenterid}/{stepid}", method="PUT", auth_required=False)
|
||||||
|
|
Loading…
Reference in a new issue