Ejemplo n.º 1
0
def lights():
    if not request.forms:        # GET
        return lightbot.status()

    # POST
    obj = request.forms
    func = getattr(lightbot, "lights_%s" % obj.get('action', ''), None)
    if not func:
        log.debug("action '%s' not found" % obj.get('action', ''))
        return {'error': "action '%s' not found" % obj.get('action', '')}

    # only keyword arguments allowed
    kwargs = {}
    spec = inspect.getargspec(func)
    for variable in spec.args:
        value = obj.get(variable, None)
        if not value is None:
            kwargs[variable] = value

    try:
        func(**kwargs)
    except:
        log.exception()
    return lightbot.status()
Ejemplo n.º 2
0
def status():
    status = {}
    status['lights'] = lightbot.status()
    status['programs'] = programs.status()
    return status