예제 #1
0
파일: server.py 프로젝트: andythigpen/x10
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()
예제 #2
0
파일: server.py 프로젝트: andythigpen/x10
def status():
    status = {}
    status['lights'] = lightbot.status()
    status['programs'] = programs.status()
    return status