diff options
author | Karel Kočí <cynerd@email.cz> | 2017-06-17 10:54:20 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-06-17 10:54:20 +0200 |
commit | cfc9a152f42366d6e8fecf3134a9824840c80acc (patch) | |
tree | 99da8bbf5c24a07a94600c08b3ae0923ed99ee3f /foris/__init__.py | |
download | turris-ups-pfc8591-cfc9a152f42366d6e8fecf3134a9824840c80acc.tar.gz turris-ups-pfc8591-cfc9a152f42366d6e8fecf3134a9824840c80acc.tar.bz2 turris-ups-pfc8591-cfc9a152f42366d6e8fecf3134a9824840c80acc.zip |
Initial commit
Diffstat (limited to 'foris/__init__.py')
-rw-r--r-- | foris/__init__.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/foris/__init__.py b/foris/__init__.py new file mode 100644 index 0000000..a70f760 --- /dev/null +++ b/foris/__init__.py @@ -0,0 +1,59 @@ +import os +import time + +from foris.config import ConfigPageMixin, add_config_page +from foris.config_handlers import BaseConfigHandler +from foris.core import gettext_dummy as gettext, ugettext as _ +from foris.plugins import ForisPlugin +from foris.ubus import call as ubus_call + + +class SamplePluginConfigHandler(BaseConfigHandler): + pass + + +class SamplePluginPage(ConfigPageMixin, SamplePluginConfigHandler): + menu_order = 70 + template = "i2c_collect/i2c_collect.tpl" + userfriendly_title = gettext("I2C collect") + + def _prepare_render_args(self, args): + args['PLUGIN_NAME'] = SamplePluginPlugin.PLUGIN_NAME + args['PLUGIN_STYLES'] = SamplePluginPlugin.PLUGIN_STYLES + args['PLUGIN_STATIC_SCRIPTS'] = SamplePluginPlugin.PLUGIN_STATIC_SCRIPTS + 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'] + for _, dt in enumerate(args['data'][fld]): + dt[0] = time.strftime('%H:%M:%S', time.gmtime(int(dt[0]))) + if fld == "voltage": + dt[1] = float(dt[1]) * 0.0593 + elif fld == "light": + dt[1] = float(255 - dt[1]) # TODO calibrate + elif fld == "temperature": + dt[1] = float(255 - dt[1]) # TODO calibrate + elif fld == "trimmer": + dt[1] = float(dt[1]) / 2.55 + + def render(self, **kwargs): + self._prepare_render_args(kwargs) + return super(SamplePluginPage, self).render(**kwargs) + + +class SamplePluginPlugin(ForisPlugin): + PLUGIN_NAME = "i2c_collect" + DIRNAME = os.path.dirname(os.path.abspath(__file__)) + + PLUGIN_STYLES = [ + ] + PLUGIN_STATIC_SCRIPTS = [ + "js/Chart.bundle.min.js" + ] + PLUGIN_DYNAMIC_SCRIPTS = [ + "i2c_collect.js" + ] + + def __init__(self, app): + super(SamplePluginPlugin, self).__init__(app) + add_config_page("i2c_collect", SamplePluginPage, top_level=True) |