mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 22:48:16 +01:00
fixes for step controller
This commit is contained in:
parent
8cf373c993
commit
017b7373e3
14 changed files with 588 additions and 377 deletions
File diff suppressed because it is too large
Load diff
|
@ -35,7 +35,7 @@ class ActorController(CRUDController):
|
|||
return dict(items=self.cache,types=self.types)
|
||||
|
||||
async def _init_actor(self, actor):
|
||||
|
||||
print("INit ACTOR")
|
||||
try:
|
||||
if actor.type in self.types:
|
||||
cfg = actor.config.copy()
|
||||
|
@ -43,6 +43,7 @@ class ActorController(CRUDController):
|
|||
clazz = self.types[actor.type]["class"];
|
||||
self.cache[actor.id].instance = clazz(**cfg)
|
||||
self.cache[actor.id].instance.init()
|
||||
print(actor.id, self.cache[actor.id].instance)
|
||||
await self.cbpi.bus.fire(topic="actor/%s/initialized" % actor.id, id=actor.id)
|
||||
else:
|
||||
self.logger.error("Actor type '%s' not found (Available Actor Types: %s)" % (actor.type, ', '.join(self.types.keys())))
|
||||
|
@ -146,4 +147,4 @@ class ActorController(CRUDController):
|
|||
await self._stop_actor(actor)
|
||||
|
||||
async def _post_update_callback(self, actor):
|
||||
self._init_actor(actor)
|
||||
await self._init_actor(actor)
|
||||
|
|
|
@ -154,3 +154,11 @@ class KettleController(CRUDController):
|
|||
sensor_id = kettle.sensor
|
||||
|
||||
return await self.cbpi.sensor.get_value(sensor_id)
|
||||
|
||||
@on_event(topic="kettle/+/targettemp")
|
||||
async def set_target_temp(self, kettle_id, target_temp, **kwargs) -> None:
|
||||
|
||||
kettle = self.cache[int(kettle_id)]
|
||||
kettle.target_temp = int(target_temp)
|
||||
await self.model.update(**kettle.__dict__)
|
||||
await self.cbpi.bus.fire("kettle/%s/targettemp/set" % kettle_id)
|
|
@ -63,7 +63,7 @@ class PluginController():
|
|||
this_directory = os.path.dirname(__file__)
|
||||
with open("./config/plugin_list.txt") as f:
|
||||
|
||||
print("###### LAD")
|
||||
|
||||
plugins = f.read().splitlines()
|
||||
plugins = list(set(plugins))
|
||||
|
||||
|
|
|
@ -56,8 +56,8 @@ class StepController(CRUDController):
|
|||
self.current_job = await self.cbpi.job.start_job(self.current_step.run(), step.name, "step")
|
||||
|
||||
|
||||
def get_state(self):
|
||||
return dict(items=self.get_all(),types=self.types,is_running=self.is_running(),current_step=self.current_step)
|
||||
async def get_state(self):
|
||||
return dict(items=await self.get_all(),types=self.types,is_running=self.is_running(),current_step=self.current_step)
|
||||
|
||||
@on_event("step/action")
|
||||
async def handle_action(self, action, **kwargs):
|
||||
|
|
|
@ -15,13 +15,13 @@ class SystemController():
|
|||
self.cbpi.register(self, "/system")
|
||||
|
||||
@request_mapping("/", method="GET", auth_required=False)
|
||||
def state(self, request):
|
||||
async def state(self, request):
|
||||
# TODO implement restart
|
||||
return web.json_response(data=dict(
|
||||
actor=self.cbpi.actor.get_state(),
|
||||
sensor=self.cbpi.sensor.get_state(),
|
||||
kettle=self.cbpi.kettle.get_state(),
|
||||
step=self.cbpi.step.get_state(),
|
||||
step=await self.cbpi.step.get_state(),
|
||||
dashboard=self.cbpi.dashboard.get_state(),
|
||||
translations=self.cbpi.translation.get_all(),
|
||||
config=self.cbpi.config.get_state())
|
||||
|
|
|
@ -115,7 +115,8 @@ class CBPiEventBus(object):
|
|||
|
||||
futures = {}
|
||||
|
||||
print("FIRE",topic, kwargs)
|
||||
|
||||
self.logger.info("FIRE %s %s" % (topic, kwargs))
|
||||
|
||||
async def wait(futures):
|
||||
if(len(futures) > 0):
|
||||
|
|
|
@ -36,6 +36,7 @@ class CustomActor(CBPiActor):
|
|||
self.state = False
|
||||
|
||||
def get_state(self):
|
||||
|
||||
return self.state
|
||||
|
||||
|
||||
|
|
|
@ -39,10 +39,11 @@ class HttpCrudEndpoints():
|
|||
|
||||
@request_mapping(path="/{id}", method="PUT", auth_required=False)
|
||||
async def http_update(self, request):
|
||||
id = request.match_info['id']
|
||||
id = int(request.match_info['id'])
|
||||
data = await request.json()
|
||||
obj = await self.controller.update(id, data)
|
||||
return web.json_response(obj, dumps=json_dumps)
|
||||
print("PRINT",await self.controller.get_one(id))
|
||||
return web.json_response(await self.controller.get_one(id), dumps=json_dumps)
|
||||
|
||||
@request_mapping(path="/{id}", method="DELETE", auth_required=False)
|
||||
async def http_delete_one(self, request):
|
||||
|
|
|
@ -180,6 +180,8 @@ class DashBoardHttpEndpoints(HttpCrudEndpoints):
|
|||
description: successful operation
|
||||
"""
|
||||
data = await request.json()
|
||||
|
||||
data["dbid"] = int(request.match_info['id'])
|
||||
return web.json_response(await self.cbpi.dashboard.add_content(data), dumps=json_dumps)
|
||||
|
||||
|
||||
|
@ -214,7 +216,7 @@ class DashBoardHttpEndpoints(HttpCrudEndpoints):
|
|||
|
||||
|
||||
|
||||
@request_mapping(path="/{id:\d+}/content/{content_id:\d+}/move", method="PUT", auth_required=False)
|
||||
@request_mapping(path="/{id:\d+}/content/{content_id:\d+}/move", method="POST", auth_required=False)
|
||||
async def move_content(self,request):
|
||||
"""
|
||||
---
|
||||
|
@ -252,8 +254,9 @@ class DashBoardHttpEndpoints(HttpCrudEndpoints):
|
|||
description: successful operation
|
||||
"""
|
||||
data = await request.json()
|
||||
schema = Schema({"x": int, "y": int})
|
||||
schema = Schema({"id": int, "x": int, "y": int})
|
||||
schema(data)
|
||||
content_id = int(request.match_info['content_id'])
|
||||
print("MOVE",content_id)
|
||||
return web.json_response(await self.cbpi.dashboard.move_content(content_id,data["x"], data["y"]), dumps=json_dumps)
|
||||
|
||||
|
|
|
@ -280,6 +280,29 @@ class KettleHttpEndpoints(HttpCrudEndpoints):
|
|||
temp = await self.controller.get_traget_temp(kettle_id)
|
||||
return web.json_response(data=dict(target_temp=temp, kettle_id=kettle_id))
|
||||
|
||||
@request_mapping(path="/{id:\d+}/temp/{temp:\d+}", method="PUT", auth_required=False)
|
||||
async def http_set_taget_temp(self, request):
|
||||
"""
|
||||
---
|
||||
description: Get Target Temp of kettle
|
||||
tags:
|
||||
- Kettle
|
||||
parameters:
|
||||
- name: "id"
|
||||
in: "path"
|
||||
description: "Kettle ID"
|
||||
required: true
|
||||
type: "integer"
|
||||
format: "int64"
|
||||
responses:
|
||||
"204":
|
||||
description: successful operation
|
||||
"""
|
||||
kettle_id = int(request.match_info['id'])
|
||||
target_temp = int(request.match_info['temp'])
|
||||
await self.cbpi.bus.fire(topic="kettle/%s/targettemp" % kettle_id, kettle_id=kettle_id, target_temp=target_temp)
|
||||
return web.Response(status=204)
|
||||
|
||||
@request_mapping(path="/{id:\d+}/temp", auth_required=False)
|
||||
async def http_temp(self, request):
|
||||
"""
|
||||
|
@ -300,5 +323,6 @@ class KettleHttpEndpoints(HttpCrudEndpoints):
|
|||
"""
|
||||
kettle_id = int(request.match_info['id'])
|
||||
temp = await self.controller.get_temp(kettle_id)
|
||||
return web.json_response(data=dict(temp=temp, kettle_id=kettle_id))
|
||||
|
||||
return web.Response(status=204)
|
||||
|
||||
|
|
|
@ -12,12 +12,18 @@ class ComplexEncoder(JSONEncoder):
|
|||
try:
|
||||
|
||||
if isinstance(obj, ActorModel):
|
||||
data = dict(**obj.__dict__, state=obj.instance.get_state())
|
||||
print(obj.instance)
|
||||
print("DATA", obj.__dict__)
|
||||
data = dict(**obj.__dict__)
|
||||
data["state"] = obj.instance.get_state()
|
||||
del data["instance"]
|
||||
|
||||
return data
|
||||
|
||||
elif isinstance(obj, SensorModel):
|
||||
data = dict(**obj.__dict__, state=obj.instance.get_state(), value=obj.instance.get_value())
|
||||
data = dict(**obj.__dict__)
|
||||
data["value"] = value=obj.instance.get_value()
|
||||
data["state"] = obj.instance.get_state()
|
||||
del data["instance"]
|
||||
return data
|
||||
#elif callable(getattr(obj, "reprJSON")):
|
||||
|
@ -28,6 +34,7 @@ class ComplexEncoder(JSONEncoder):
|
|||
# return obj()
|
||||
else:
|
||||
raise TypeError()
|
||||
except TypeError:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
return None
|
||||
|
|
|
@ -21,22 +21,10 @@ class CBPiWebSocket:
|
|||
self.cbpi.bus.register_object(self)
|
||||
|
||||
#if self.cbpi.config.static.get("ws_push_all", False):
|
||||
#self.cbpi.bus.register("#", self.listen)
|
||||
self.patters = {}
|
||||
#self.add_mapper("(actor)\/([\d])\/(on|toggle|off)\/(ok)$", self.map_actor)
|
||||
|
||||
def add_mapper(self, pattern, method):
|
||||
self.patters[re.compile(pattern)] = method
|
||||
|
||||
async def map_actor(self, regex_result, **kwargs):
|
||||
|
||||
actor_id = int(regex_result.group(2))
|
||||
return dict(topic="ACTOR_UPDATE", data=await self.cbpi.actor.get_one(actor_id))
|
||||
|
||||
self.cbpi.bus.register("#", self.listen)
|
||||
|
||||
|
||||
async def listen(self, topic, **kwargs):
|
||||
|
||||
data = dict(topic=topic, data=dict(**kwargs))
|
||||
self.logger.debug("PUSH %s " % data)
|
||||
self.send(data)
|
||||
|
|
BIN
craftbeerpi.db
BIN
craftbeerpi.db
Binary file not shown.
Loading…
Reference in a new issue