From 8e8481885d3134e8d994a30fd5254fc6d41df9ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Tue, 15 Aug 2017 17:57:25 +0200 Subject: Rename from i2c-collect to more suitable ups-pfc8591 --- daemon.py | 6 +- foris/__init__.py | 10 +-- foris/templates/i2c_collect/i2c_collect.tpl | 33 --------- .../javascript/i2c_collect/i2c_collect.js.tpl | 78 ---------------------- .../javascript/ups_pfc8591/ups_pfc8591.js.tpl | 78 ++++++++++++++++++++++ foris/templates/ups_pfc8591/ups_pfc8591.tpl | 33 +++++++++ 6 files changed, 119 insertions(+), 119 deletions(-) delete mode 100644 foris/templates/i2c_collect/i2c_collect.tpl delete mode 100644 foris/templates/javascript/i2c_collect/i2c_collect.js.tpl create mode 100644 foris/templates/javascript/ups_pfc8591/ups_pfc8591.js.tpl create mode 100644 foris/templates/ups_pfc8591/ups_pfc8591.tpl diff --git a/daemon.py b/daemon.py index dfa9bfa..5fb966f 100755 --- a/daemon.py +++ b/daemon.py @@ -22,7 +22,7 @@ battery_not_high = 250 i2c = I2C("/dev/i2c-7") # Initialize sqlite -db_connection = sqlite3.connect('/tmp/i2c-collect.db') +db_connection = sqlite3.connect('/tmp/ups-pfc8591.db') db = db_connection.cursor() # Initialize ubus @@ -36,7 +36,7 @@ def read_chunk(handler, data): handler.reply({"data": result}) ubus.add( - "i2c-collect", { + "ups-pfc8591", { "read_data": { "method": read_chunk, "signature": {"range": ubus.BLOBMSG_TYPE_INT32, "field": ubus.BLOBMSG_TYPE_STRING}, @@ -73,7 +73,7 @@ def db_data(data): def ubus_data(data): date = str(int(time.time())) for k in iter(data.keys()): - ubus.send("i2c-collect", {k: (date, data[k])}) + ubus.send("ups-pfc8591", {k: (date, data[k])}) notified_power_supply = False notified_low_battery = False diff --git a/foris/__init__.py b/foris/__init__.py index a70f760..8eff4ce 100644 --- a/foris/__init__.py +++ b/foris/__init__.py @@ -14,7 +14,7 @@ class SamplePluginConfigHandler(BaseConfigHandler): class SamplePluginPage(ConfigPageMixin, SamplePluginConfigHandler): menu_order = 70 - template = "i2c_collect/i2c_collect.tpl" + template = "ups_pfc8591/ups_pfc8591.tpl" userfriendly_title = gettext("I2C collect") def _prepare_render_args(self, args): @@ -24,7 +24,7 @@ class SamplePluginPage(ConfigPageMixin, SamplePluginConfigHandler): args['PLUGIN_DYNAMIC_SCRIPTS'] = SamplePluginPlugin.PLUGIN_DYNAMIC_SCRIPTS args['data'] = {} for fld in ["voltage", "light", "temperature", "trimmer"]: - args['data'][fld] = ubus_call("i2c-collect", "read_data", {"range": 172800, "field": fld})[0]['data'] + args['data'][fld] = ubus_call("ups-pfc8591", "read_data", {"range": 172800, "field": fld})[0]['data'] for _, dt in enumerate(args['data'][fld]): dt[0] = time.strftime('%H:%M:%S', time.gmtime(int(dt[0]))) if fld == "voltage": @@ -42,7 +42,7 @@ class SamplePluginPage(ConfigPageMixin, SamplePluginConfigHandler): class SamplePluginPlugin(ForisPlugin): - PLUGIN_NAME = "i2c_collect" + PLUGIN_NAME = "ups_pfc8591" DIRNAME = os.path.dirname(os.path.abspath(__file__)) PLUGIN_STYLES = [ @@ -51,9 +51,9 @@ class SamplePluginPlugin(ForisPlugin): "js/Chart.bundle.min.js" ] PLUGIN_DYNAMIC_SCRIPTS = [ - "i2c_collect.js" + "ups_pfc8591.js" ] def __init__(self, app): super(SamplePluginPlugin, self).__init__(app) - add_config_page("i2c_collect", SamplePluginPage, top_level=True) + add_config_page("ups_pfc8591", SamplePluginPage, top_level=True) diff --git a/foris/templates/i2c_collect/i2c_collect.tpl b/foris/templates/i2c_collect/i2c_collect.tpl deleted file mode 100644 index 12226a5..0000000 --- a/foris/templates/i2c_collect/i2c_collect.tpl +++ /dev/null @@ -1,33 +0,0 @@ - -%rebase("config/base.tpl", **locals()) - -
-%include("_messages.tpl") -
-%for fld in ["voltage", "light", "temperature", "trimmer"]: - -%end -
-
- - - diff --git a/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl b/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl deleted file mode 100644 index 0ca8108..0000000 --- a/foris/templates/javascript/i2c_collect/i2c_collect.js.tpl +++ /dev/null @@ -1,78 +0,0 @@ -function graph_init(field) { - var graph_config = { - type: 'line', - data: { - labels: graph_labels[field], - datasets: [ - { - label: field, - data: graph_data[field], - }, - ], - fill: false, - steppedLine: false, - }, - options: { - responsive: true, - title: { - display:true, - text:'{{ trans("Sample") }}' - }, - tooltips: { - mode: 'index', - intersect: false, - }, - hover: { - mode: 'nearest', - intersect: true - }, - scales: { - xAxes: [{ - display: true, - scaleLabel: { - display: true, - labelString: '{{ trans("Time") }}' - } - }], - yAxes: [{ - display: true, - scaleLabel: { - display: true, - labelString: '{{ trans("Value") }}' - } - }], - }, - }, - }; - if (field == "voltage") { - graph_config.options.scales.yAxes[0].ticks = { min: 10, max: 15 } - } else if (field == "light" || field == "temperature") { - graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 250 } - } else if (field == "light" || field == "temperature") { - graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 100 } - } - var graph_ctx = document.getElementById("canvas-" + field).getContext("2d"); - Foris.lineChart[field] = new Chart(graph_ctx, graph_config); - Foris.lineChartData[field] = graph_config.data; -} - -$(document).ready(function() { - Foris.lineChart = []; - Foris.lineChartData = []; - graph_init("voltage"); - graph_init("light"); - graph_init("temperature"); - graph_init("trimmer"); -}); - -/* -Foris.WS["i2c-collect"] = function (data) { - for (d in data) { - Foris.lineChartData[d].datasets[0].data.push(data[d][0]); - Foris.lineChartData[d].datasets[0].data.shift(); - Foris.lineChartData[d].labels.push(data[d][1]); - Foris.lineChartData[d].labels.shift(); - Foris.lineChart[d].update(); - } -}; -*/ diff --git a/foris/templates/javascript/ups_pfc8591/ups_pfc8591.js.tpl b/foris/templates/javascript/ups_pfc8591/ups_pfc8591.js.tpl new file mode 100644 index 0000000..5ee281d --- /dev/null +++ b/foris/templates/javascript/ups_pfc8591/ups_pfc8591.js.tpl @@ -0,0 +1,78 @@ +function graph_init(field) { + var graph_config = { + type: 'line', + data: { + labels: graph_labels[field], + datasets: [ + { + label: field, + data: graph_data[field], + }, + ], + fill: false, + steppedLine: false, + }, + options: { + responsive: true, + title: { + display:true, + text:'{{ trans("Sample") }}' + }, + tooltips: { + mode: 'index', + intersect: false, + }, + hover: { + mode: 'nearest', + intersect: true + }, + scales: { + xAxes: [{ + display: true, + scaleLabel: { + display: true, + labelString: '{{ trans("Time") }}' + } + }], + yAxes: [{ + display: true, + scaleLabel: { + display: true, + labelString: '{{ trans("Value") }}' + } + }], + }, + }, + }; + if (field == "voltage") { + graph_config.options.scales.yAxes[0].ticks = { min: 10, max: 15 } + } else if (field == "light" || field == "temperature") { + graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 250 } + } else if (field == "light" || field == "temperature") { + graph_config.options.scales.yAxes[0].ticks = { min: 0, max: 100 } + } + var graph_ctx = document.getElementById("canvas-" + field).getContext("2d"); + Foris.lineChart[field] = new Chart(graph_ctx, graph_config); + Foris.lineChartData[field] = graph_config.data; +} + +$(document).ready(function() { + Foris.lineChart = []; + Foris.lineChartData = []; + graph_init("voltage"); + graph_init("light"); + graph_init("temperature"); + graph_init("trimmer"); +}); + +/* +Foris.WS["ups-pfc8591"] = function (data) { + for (d in data) { + Foris.lineChartData[d].datasets[0].data.push(data[d][0]); + Foris.lineChartData[d].datasets[0].data.shift(); + Foris.lineChartData[d].labels.push(data[d][1]); + Foris.lineChartData[d].labels.shift(); + Foris.lineChart[d].update(); + } +}; +*/ diff --git a/foris/templates/ups_pfc8591/ups_pfc8591.tpl b/foris/templates/ups_pfc8591/ups_pfc8591.tpl new file mode 100644 index 0000000..e2ae1ef --- /dev/null +++ b/foris/templates/ups_pfc8591/ups_pfc8591.tpl @@ -0,0 +1,33 @@ + +%rebase("config/base.tpl", **locals()) + +
+%include("_messages.tpl") +
+%for fld in ["voltage", "light", "temperature", "trimmer"]: + +%end +
+
+ + + -- cgit v1.2.3