Esempio n. 1
0
def api_module_field_status(module_name, field_name):
    if not packaging.is_installed(module_name):
        abort(404)

    try:
        mod = use_module(module_name)
    except RuntimeError as e:
        app.logger.exception(e)
        abort(404)
    else:
        # field exists ?
        if not field_name in mod.fields_info:
            abort(400)

        # field is readable ?
        f = mod.fields_info[field_name]
        if 'readable' not in f or not f['readable']:
            abort(403)

        # field returns value ?
        value = getattr(mod, f['name'])()
        if value is None:
            abort(404)

        return jsonify(dict(zip(('time', 'value'), value)))
Esempio n. 2
0
File: app.py Progetto: TurpIF/KHome
def api_module_field_status(module_name, field_name):
    if not packaging.is_installed(module_name):
        abort(404)

    try:
        mod = use_module(module_name)
    except RuntimeError as e:
        app.logger.exception(e)
        abort(404)
    else:
        # field exists ?
        if not field_name in mod.fields_info:
            abort(400)

        # field is readable ?
        f = mod.fields_info[field_name]
        if 'readable' not in f or not f['readable']:
            abort(403)

        # field returns value ?
        value = getattr(mod, f['name'])()
        if value is None:
            abort(404)

        return jsonify(dict(zip(('time', 'value'), value)))
Esempio n. 3
0
def api_module_fields_all_statuses(module_name, field_name):
    if not packaging.is_installed(module_name):
        app.logger.warning('%s not installed', module_name)
        abort(404)
    try:
        mod = use_module(module_name)
    except RuntimeError as e:
        app.logger.exception(e)
        abort(404)
    else:
        if not field_name in mod.fields_info:
            abort(400)

        f = mod.fields_info[field_name]
        if 'readable' not in f or not f['readable']:
            abort(400)

        data = getattr(mod, f['name'])(fr=-time.time(), to=0)
        return jsonify([dict(zip(('time', 'value'), v)) for v in data])
Esempio n. 4
0
File: app.py Progetto: TurpIF/KHome
def api_module_fields_all_statuses(module_name, field_name):
    if not packaging.is_installed(module_name):
        app.logger.warning('%s not installed', module_name)
        abort(404)
    try:
        mod = use_module(module_name)
    except RuntimeError as e:
        app.logger.exception(e)
        abort(404)
    else:
        if not field_name in mod.fields_info:
            abort(400)

        f = mod.fields_info[field_name]
        if 'readable' not in f or not f['readable']:
            abort(400)

        data = getattr(mod, f['name'])(fr=-time.time(), to=0)
        return jsonify([dict(zip(('time', 'value'), v)) for v in data])
Esempio n. 5
0
def api_module_status(module_name):
    # TODO add support for multiple instances
    if not packaging.is_installed(module_name):
        app.logger.warning('%s not installed', module_name)
        abort(404)
    try:
        mod = use_module(module_name)
        mod.info['name'] = path.realname(mod.info['name'])  # hack
    except RuntimeError as e:
        app.logger.exception(e)
        abort(404)
    else:
        fields = {}
        for f in mod.info['fields']:
            if 'readable' not in f or not f['readable']:
                continue
            value = getattr(mod, f['name'])()
            if value is None:
                continue
            f.update(dict(zip(('time', 'value'), value)))
        return jsonify(mod.info)
Esempio n. 6
0
File: app.py Progetto: TurpIF/KHome
def api_module_status(module_name):
    # TODO add support for multiple instances
    if not packaging.is_installed(module_name):
        app.logger.warning('%s not installed', module_name)
        abort(404)
    try:
        mod = use_module(module_name)
        mod.info['name'] = path.realname(mod.info['name']) # hack
    except RuntimeError as e:
        app.logger.exception(e)
        abort(404)
    else:
        fields = {}
        for f in mod.info['fields']:
            if 'readable' not in f or not f['readable']:
                continue
            value = getattr(mod, f['name'])()
            if value is None:
                continue
            f.update(dict(zip(('time', 'value'), value)))
        return jsonify(mod.info)