Action Button for Sensors added

This commit is contained in:
Manuel83
2017-07-05 21:16:40 +02:00
parent 62f31e2dd4
commit 3af76d0a1e
3 changed files with 42 additions and 28 deletions
+10 -1
View File
@@ -267,7 +267,7 @@ class CraftBeerPi(ActorAPI, SensorAPI):
# helper method for parsing props # helper method for parsing props
def __parseProps(self, key, cls): def __parseProps(self, key, cls):
name = cls.__name__ name = cls.__name__
self.cache[key][name] = {"name": name, "class": cls, "properties": []} self.cache[key][name] = {"name": name, "class": cls, "properties": [], "actions": []}
tmpObj = cls() tmpObj = cls()
members = [attr for attr in dir(tmpObj) if not callable(getattr(tmpObj, attr)) and not attr.startswith("__")] members = [attr for attr in dir(tmpObj) if not callable(getattr(tmpObj, attr)) and not attr.startswith("__")]
for m in members: for m in members:
@@ -283,6 +283,13 @@ class CraftBeerPi(ActorAPI, SensorAPI):
t = tmpObj.__getattribute__(m) t = tmpObj.__getattribute__(m)
self.cache[key][name]["properties"].append( self.cache[key][name]["properties"].append(
{"name": m, "label": t.label, "type": "select", "configurable": True, "options": t.options}) {"name": m, "label": t.label, "type": "select", "configurable": True, "options": t.options})
for name, method in cls.__dict__.iteritems():
if hasattr(method, "action"):
label = method.__getattribute__("label")
self.cache[key][cls.__name__]["actions"].append({"method": name, "label": label})
return cls return cls
@@ -315,6 +322,8 @@ class CraftBeerPi(ActorAPI, SensorAPI):
def get_fermentation_controller(self, name): def get_fermentation_controller(self, name):
return self.cache["fermentation_controller_types"].get(name) return self.cache["fermentation_controller_types"].get(name)
# Step action # Step action
def action(self,label): def action(self,label):
def real_decorator(func): def real_decorator(func):
+5
View File
@@ -12,6 +12,11 @@ class SensorView(BaseView):
model = Sensor model = Sensor
cache_key = "sensors" cache_key = "sensors"
@route('<int:id>/action/<method>', methods=["POST"])
def action(self, id, method):
cbpi.cache.get("sensors").get(id).instance.__getattribute__(method)()
return ('', 204)
def _post_post_callback(self, m): def _post_post_callback(self, m):
cbpi.init_sensor(m.id) cbpi.init_sensor(m.id)
File diff suppressed because one or more lines are too long