def dashboard_view(request): lamps=[] lamps_state = smart.get_state() lamps.append(lamp_state(0, lamps_state & 1 == 1)) lamps.append(lamp_state(1, lamps_state & 2 == 2)) return {'time':time.asctime(),'lamps':lamps,'lamp_state':lamps_state}
def lights_cmd(request): cmd = request.matchdict["cmd"] idx = int(request.matchdict["idx"]) intf = smart.get_interface() if not intf: request.session.flash(u"Аппаратный сбой!") return HTTPFound(location=request.route_url('dashboard')) state = smart.get_state() if cmd == 'toggle': if idx<0: if state: smart.turn_off(intf) else: smart.turn_on(intf) else: state = state ^ (1<<idx) smart.set_state(state, intf) return HTTPFound(location=request.route_url('dashboard'))