diff options
author | Russell Morris <rmorris@rkmorris.us> | 2020-01-22 21:10:13 -0600 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-07-18 15:28:36 +0200 |
commit | dcac704b3d6bc3c4ad2ccacb3d79fc67d900087f (patch) | |
tree | c384a20a949b737946b677e72e3b3a8d1fc84c7c /modules/luci-mod-battstatus/htdocs | |
parent | df3f62988897012b36c1f4810570a1eece65e2d5 (diff) |
luci-app-battstatus: initial release
Introduce a new package luci-app-battstatus which queries battery charge
information using i2c commands and displays a charge indicator in the
upper right notification area.
So far this package has been tested to work with the HooToo HT-TM05
travel router but might be extended to cover further models in the
future.
Signed-off-by: Russell Morris <rmorris@rkmorris.us>
[rebase on top of master, rewrite commit message, adjust copyright,
convert some ubus fields to boolean values]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-mod-battstatus/htdocs')
-rwxr-xr-x | modules/luci-mod-battstatus/htdocs/luci-static/resources/preload/battstatus.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/modules/luci-mod-battstatus/htdocs/luci-static/resources/preload/battstatus.js b/modules/luci-mod-battstatus/htdocs/luci-static/resources/preload/battstatus.js new file mode 100755 index 0000000000..d895c36bbd --- /dev/null +++ b/modules/luci-mod-battstatus/htdocs/luci-static/resources/preload/battstatus.js @@ -0,0 +1,55 @@ +'use strict'; +'require ui'; +'require rpc'; +'require poll'; +'require baseclass'; + +var callBatteryStatus = rpc.declare({ + object: 'luci.battstatus', + method: 'getBatteryStatus', + expect: { '': {} } +}); + +var devices = {}; + +return baseclass.extend({ + __init__: function() { + this.updateIndicator(); + poll.add(L.bind(this.updateIndicator, this), 5); + }, + + updateIndicator: function() { + return callBatteryStatus().then(L.bind(function(devs) { + for (var dev in devs) { + var info = devs[dev]; + if (info.valid) { + info.status = (info.charging ? _('Charging') : _('Not Charging')) + ": " + info.percentage + "%"; + info.state = "active"; + if (info.percentage <= 20) + info.color = "Red"; + else if (info.percentage <= 30) + info.color = "GoldenRod"; + } else { + info.status = info.message; + info.state = "inactive"; + } + + info.name = "battery-" + dev.replace(" ", "-"); + ui.showIndicator(info.name, info.status, null, info.state); + if (typeof info.color != 'undefined') { + info.element = document.querySelector(`[data-indicator="${info.name}"]`); + info.element.innerHTML = `<span style="color:${info.color}">${info.status}</span>`; + } + + devices[dev] = info; + } + + for (var dev in devices) { + if (!devs.hasOwnProperty(dev)) { + ui.hideIndicator('battery-%s'.format(dev)); + delete devices[dev]; + } + } + }, this)); + } +}); |