Skip to content

Commit

Permalink
Merge pull request Manuel83#94 from carlallen/modify_charts_in_plugins
Browse files Browse the repository at this point in the history
Allow modifying chart data in plugins
  • Loading branch information
Manuel83 authored Jul 22, 2017
2 parents 1f1f840 + 01997f7 commit 2fe3d1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
15 changes: 15 additions & 0 deletions modules/core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def run(self):

class KettleController(ControllerBase, ActorController, SensorController):

@staticmethod
def chart(kettle):
result = []
result.append({"name": "Temp", "data_type": "sensor", "data_id": kettle.sensor})
result.append({"name": "Target Temp", "data_type": "kettle", "data_id": kettle.id})

return result

def __init__(self, *args, **kwds):
ControllerBase.__init__(self, *args, **kwds)
self.kettle_id = kwds.get("kettle_id")
Expand Down Expand Up @@ -107,6 +115,13 @@ def get_target_temp(self, id=None):

class FermenterController(ControllerBase, ActorController, SensorController):

@staticmethod
def chart(fermenter):
result = []
result.append({"name": "Temp", "data_type": "sensor", "data_id": fermenter.sensor})
result.append({"name": "Target Temp", "data_type": "fermenter", "data_id": fermenter.id})
return result

def __init__(self, *args, **kwds):
ControllerBase.__init__(self, *args, **kwds)
self.fermenter_id = kwds.get("fermenter_id")
Expand Down
9 changes: 5 additions & 4 deletions modules/logs/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def read_log_as_json(self, type, id):
pass
return array

def convert_chart_data_to_json(self, chart_data):
return {"name": chart_data["name"], "data": self.read_log_as_json(chart_data["data_type"], chart_data["data_id"])}

@route('/<t>/<int:id>', methods=["POST"])
def get_logs_as_json(self, t, id):
Expand All @@ -76,13 +78,12 @@ def get_logs_as_json(self, t, id):

if t == "k":
kettle = cbpi.cache.get("kettle").get(id)
result.append({"name": "Temp", "data": self.read_log_as_json("sensor", kettle.sensor)})
result.append({"name": "Target Temp", "data": self.read_log_as_json("kettle", kettle.id)})
result = map(self.convert_chart_data_to_json, cbpi.get_controller(kettle.logic).get("class").chart(kettle))

if t == "f":
fermenter = cbpi.cache.get("fermenter").get(id)
result.append({"name": "Temp", "data": self.read_log_as_json("sensor", fermenter.sensor)})
result.append({"name": "Target Temp", "data": self.read_log_as_json("fermenter", fermenter.id)})
result = map(self.convert_chart_data_to_json, cbpi.get_fermentation_controller(fermenter.logic).get("class").chart(fermenter))

return json.dumps(result)

@route('/download/<file>')
Expand Down

0 comments on commit 2fe3d1d

Please sign in to comment.