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()
def status(): status = {} status['lights'] = lightbot.status() status['programs'] = programs.status() return status