async def http_add(self, request): """ --- description: Add tags: - Step parameters: - in: body name: body description: Created an step required: true schema: type: object responses: "200": description: successful operation """ data = await request.json() step = Step(name=data.get("name"), props=Props(data.get("props", {})), type=data.get("type")) response_data = await self.controller.add(step) return web.json_response(data=response_data.to_dict())
async def http_update(self, request): """ --- description: Update an actor tags: - Actor parameters: - name: "id" in: "path" description: "Actor ID" required: true type: "integer" format: "int64" - in: body name: body description: Update an actor required: false schema: type: object properties: name: type: string type: type: string config: props: object responses: "200": description: successful operation """ id = request.match_info['id'] data = await request.json() actor = Actor(id=id, name=data.get("name"), props=Props(data.get("props", {})), type=data.get("type")) return web.json_response(data=(await self.controller.update(actor)).to_dict())
def _create_step(self, fermenter, item): id = item.get("id") name = item.get("name") props = Props(item.get("props")) try: endtime = int(item.get("endtime", 0)) except: endtime = 0 status = StepState(item.get("status", "I")) if status == StepState.ACTIVE: status = StepState("S") type = item.get("type") try: type_cfg = self.steptypes.get(type) clazz = type_cfg.get("class") instance = clazz(self.cbpi, fermenter, item, props, self._done) except Exception as e: logging.warning("Failed to create step instance %s - %s" % (id, e)) instance = None step = FermenterStep(id=id, name=name, fermenter=fermenter, props=props, type=type, status=status, endtime=endtime, instance=instance) return step
def create_step(self, id, item): try: stepid = shortuuid.uuid() 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") instance = clazz(self.cbpi, fermenter, item, props, self._done) 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, endtime=endtime, instance=instance) return step except Exception as e: self.logger.error(e)
def _create(self, data): try: id = data.get("id") name = data.get("name") sensor = data.get("sensor") pressure_sensor = data.get("pressure_sensor") heater = data.get("heater") cooler = data.get("cooler") valve = data.get("valve", "") logictype = data.get("type") temp = data.get("target_temp") pressure = data.get("target_pressure") brewname = data.get("brewname") description = data.get("description") props = Props(data.get("props", {})) fermenter = Fermenter(id, name, sensor, pressure_sensor, heater, cooler, valve, brewname, description, props, temp, pressure, logictype) fermenter.steps = list( map(lambda item: self._create_step(fermenter, item), data.get("steps", []))) self.push_update() return fermenter except: return
def create(self, data): return Kettle(data.get("id"), data.get("name"), type=data.get("type"), props=Props(data.get("props", {})), sensor=data.get("sensor"), heater=data.get("heater"), agitator=data.get("agitator"))
def create(self, data): id = data.get("id") name = data.get("name") type = data.get("type") status = StepState(data.get("status", "I")) props = data.get("props", {}) try: type_cfg = self.types.get(type) clazz = type_cfg.get("class") instance = clazz(self.cbpi, id, name, Props(props), self.done) except Exception as e: logging.warning("Failed to create step instance %s - %s" % (id, e)) instance = None return Step(id, name, type=type, status=status, instance=instance, props=Props(props) )
def _create(self, data): id = data.get("id") name = data.get("name") brewname = data.get("brewname") props = Props(data.get("props", {})) fermenter = Fermenter(id, name, brewname, props, 0) fermenter.steps = list( map(lambda item: self._create_step(fermenter, item), data.get("steps", []))) return fermenter
async def http_add(self, request): """ --- description: add one Actor tags: - Kettle parameters: - in: body name: body description: Created an actor required: true schema: type: object properties: name: type: string sensor: type: "integer" format: "int64" heater: type: "integer" format: "int64" agitator: type: "integer" format: "int64" target_temp: type: "integer" format: "int64" type: type: string props: type: object example: name: "Kettle 1" type: "CustomKettleLogic" props: {} responses: "204": description: successful operation """ data = await request.json() kettle = Kettle(name=data.get("name"), sensor=data.get("sensor"), heater=data.get("heater"), agitator=data.get("agitator"), props=Props(data.get("props", {})), type=data.get("type")) response_data = await self.controller.add(kettle) return web.json_response(data=response_data.to_dict())
async def update_step(self, id, item): fermenter = self._find_by_id(id) stepid = item.get("id") props = item.get("props") status = StepState("I") type = item.get("type") endtime = 0 name = item.get("name") props = Props(item.get("props")) logging.info("update step") try: type_cfg = self.steptypes.get(type) logging.info(type_cfg) clazz = type_cfg.get("class") logging.info(clazz) instance = clazz(self.cbpi, fermenter, item, props, self._done) logging.info(instance) except Exception as e: logging.warning("Failed to create step instance %s - %s " % (item.id, e)) instance = None step = FermenterStep(id=stepid, name=name, fermenter=fermenter, props=props, type=type, status=status, endtime=endtime, instance=instance) try: fermenter.steps = list( map(lambda old: step if old.id == step.id else old, fermenter.steps)) except Exception as e: logging.info(e) self.save() self.push_update("fermenterstepupdate")
async def http_add(self, request): """ --- description: add one Actor tags: - Sensor parameters: - in: body name: body description: Created an actor required: true schema: type: object properties: name: type: string type: type: string props: type: object example: name: "Actor 1" type: "CustomActor" props: {} responses: "204": description: successful operation """ data = await request.json() sensor = Sensor(name=data.get("name"), props=Props(data.get("props", {})), type=data.get("type")) response_data = await self.controller.add(sensor) return web.json_response(data=response_data.to_dict())
async def http_update(self, request): """ --- description: Update tags: - Step parameters: - in: body name: body description: Created an kettle required: false schema: type: object responses: "200": description: successful operation """ data = await request.json() id = request.match_info['id'] step = Step(id, data.get("name"), Props(data.get("props", {})), data.get("type")) return web.json_response((await self.controller.update(step)).to_dict())
def create(self, data): return self.resource(data.get("id"), data.get("name"), type=data.get("type"), props=Props(data.get("props", {})) )
async def http_update(self, request): """ --- description: Update a Fermenter (NOT YET IMPLEMENTED) tags: - Fermenter parameters: - name: "id" in: "path" description: "Fermenter ID" required: true type: "integer" format: "int64" - in: body name: body description: Update a Fermenter required: false schema: type: object properties: name: type: string type: type: string config: props: object responses: "200": description: successful operation """ id = request.match_info['id'] data = await request.json() fermenter = Fermenter(id=id, name=data.get("name"), sensor=data.get("sensor"), pressure_sensor=data.get("pressure_sensor"), heater=data.get("heater"), cooler=data.get("cooler"), valve=data.get("valve"), brewname=data.get("brewname"), description=data.get("description"), target_temp=data.get("target_temp"), target_pressure=data.get("target_pressure"), props=Props(data.get("props", {})), type=data.get("type")) return web.json_response(data=(await self.controller.update(fermenter)).to_dict())
async def http_add(self, request): """ --- description: add one Fermenter tags: - Fermenter parameters: - in: body name: body description: Create a Fermenter required: true schema: type: object properties: name: type: string sensor: type: "integer" format: "int64" heater: type: "integer" format: "int64" cooler: type: "integer" format: "int64" target_temp: type: "integer" format: "int64" type: type: string props: type: object example: name: "Fermenter 1" type: "CustomFermenterLogic" sensor: "FermenterSensor" heater: "FermenterHeater" cooler: "FermenterCooler" props: {} responses: "204": description: successful operation """ data = await request.json() fermenter = Fermenter(id=id, name=data.get("name"), sensor=data.get("sensor"), pressure_sensor=data.get("pressure_sensor"), heater=data.get("heater"), cooler=data.get("cooler"), valve=data.get("valve"), brewname=data.get("brewname"), description=data.get("description"), target_temp=data.get("target_temp"), target_pressure=data.get("target_pressure"), props=Props(data.get("props", {})), type=data.get("type")) response_data = await self.controller.create(fermenter) return web.json_response(data=response_data.to_dict())