diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6044615..cb85dd7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,16 +3,18 @@
-
-
+
+
+
+
-
-
+
+
+
-
@@ -36,7 +38,7 @@
-
+
@@ -67,18 +69,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
@@ -94,18 +84,18 @@
-
+
-
-
+
+
-
+
-
+
@@ -115,19 +105,61 @@
-
-
-
-
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -136,10 +168,10 @@
-
+
-
-
+
+
@@ -147,20 +179,11 @@
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -168,36 +191,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -209,17 +202,6 @@
- _jobs.app
- /config
- job.
- from utils
- Co
- voluptuous
- pyfiglet
- from cbpi_api
- bpi.http_endpoints.http_api
- DEBUG
- PUSH
basicConfig
cbp
HALLOOOOOOO
@@ -239,6 +221,17 @@
tog
w
togll
+ INI
+ SENSOR
+ self.cache
+ SEND
+ REGISTER
+ ###### LAD
+ log
+ print
+ #######
+ get_all
+ step/brewing/stopped
@@ -251,9 +244,9 @@
$PROJECT_DIR$/tests
$PROJECT_DIR$/core/extension
$PROJECT_DIR$/core
- $PROJECT_DIR$/cbpi
$PROJECT_DIR$
$PROJECT_DIR$/cbpi/extension/ui/react/src/views/hardware
+ $PROJECT_DIR$/cbpi
@@ -262,10 +255,6 @@
@@ -350,7 +343,31 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -362,14 +379,44 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
@@ -383,14 +430,7 @@
-
-
-
-
-
-
-
-
+
@@ -398,9 +438,72 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -415,19 +518,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -476,6 +566,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -744,7 +885,7 @@
-
+
1541288846149
@@ -796,7 +937,7 @@
-
+
@@ -816,8 +957,8 @@
-
-
+
+
@@ -831,7 +972,7 @@
-
+
@@ -862,6 +1003,11 @@
149
+
+ file://$PROJECT_DIR$/cbpi/utils/encoder.py
+ 13
+
+
@@ -878,41 +1024,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -947,23 +1058,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -974,25 +1068,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1011,40 +1086,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1052,50 +1093,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1103,13 +1100,6 @@
-
-
-
-
-
-
-
@@ -1120,16 +1110,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1144,13 +1124,6 @@
-
-
-
-
-
-
-
@@ -1158,16 +1131,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1175,30 +1138,10 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -1226,16 +1169,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1243,16 +1176,229 @@
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1260,5 +1406,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/cbpi/controller/actor_controller.py b/cbpi/controller/actor_controller.py
index e3a861c..b3957f4 100644
--- a/cbpi/controller/actor_controller.py
+++ b/cbpi/controller/actor_controller.py
@@ -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)
diff --git a/cbpi/controller/kettle_controller.py b/cbpi/controller/kettle_controller.py
index 592f517..c4004d7 100644
--- a/cbpi/controller/kettle_controller.py
+++ b/cbpi/controller/kettle_controller.py
@@ -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)
\ No newline at end of file
diff --git a/cbpi/controller/plugin_controller.py b/cbpi/controller/plugin_controller.py
index 427b237..b0ac232 100644
--- a/cbpi/controller/plugin_controller.py
+++ b/cbpi/controller/plugin_controller.py
@@ -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))
diff --git a/cbpi/controller/step_controller.py b/cbpi/controller/step_controller.py
index 703a73f..f5b1fcc 100644
--- a/cbpi/controller/step_controller.py
+++ b/cbpi/controller/step_controller.py
@@ -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):
diff --git a/cbpi/controller/system_controller.py b/cbpi/controller/system_controller.py
index d7d5e12..51ce995 100644
--- a/cbpi/controller/system_controller.py
+++ b/cbpi/controller/system_controller.py
@@ -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())
diff --git a/cbpi/eventbus.py b/cbpi/eventbus.py
index 94e7079..b31157f 100644
--- a/cbpi/eventbus.py
+++ b/cbpi/eventbus.py
@@ -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):
diff --git a/cbpi/extension/dummyactor/__init__.py b/cbpi/extension/dummyactor/__init__.py
index ed73bd7..6326491 100644
--- a/cbpi/extension/dummyactor/__init__.py
+++ b/cbpi/extension/dummyactor/__init__.py
@@ -36,6 +36,7 @@ class CustomActor(CBPiActor):
self.state = False
def get_state(self):
+
return self.state
diff --git a/cbpi/http_endpoints/http_curd_endpoints.py b/cbpi/http_endpoints/http_curd_endpoints.py
index c918c1d..4501436 100644
--- a/cbpi/http_endpoints/http_curd_endpoints.py
+++ b/cbpi/http_endpoints/http_curd_endpoints.py
@@ -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):
diff --git a/cbpi/http_endpoints/http_dashboard.py b/cbpi/http_endpoints/http_dashboard.py
index fe6e94f..612e9b9 100644
--- a/cbpi/http_endpoints/http_dashboard.py
+++ b/cbpi/http_endpoints/http_dashboard.py
@@ -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)
diff --git a/cbpi/http_endpoints/http_kettle.py b/cbpi/http_endpoints/http_kettle.py
index f0f5eca..36d72e1 100644
--- a/cbpi/http_endpoints/http_kettle.py
+++ b/cbpi/http_endpoints/http_kettle.py
@@ -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)
diff --git a/cbpi/utils/encoder.py b/cbpi/utils/encoder.py
index 80d2498..de6820f 100644
--- a/cbpi/utils/encoder.py
+++ b/cbpi/utils/encoder.py
@@ -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
diff --git a/cbpi/websocket.py b/cbpi/websocket.py
index 29bdbce..7e0a680 100644
--- a/cbpi/websocket.py
+++ b/cbpi/websocket.py
@@ -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)
diff --git a/craftbeerpi.db b/craftbeerpi.db
index 218a00b..cd41b60 100644
Binary files a/craftbeerpi.db and b/craftbeerpi.db differ