env.start() env.discover() #env.wait(3) found_wemos = False for switch_name in env.list_switches(): for entry in config: if switch_name == entry.get('wemo switch'): # FIXME: log print("Found Wemo: {}".format(switch_name)) button_switches[entry['button mac']] = env.get(switch_name) found_wemos = True for bridge_name in env.list_bridges(): bridge = env.get_bridge(bridge_name) for light_name in bridge.bridge_get_lights(): for entry in config: if light_name == entry.get('wemo light'): light = Light('Garage North', bridge) # FIXME: log print("Found Wemo: {}".format(switch_name)) button_switches[entry['button mac']] = light found_wemos = True for entry in config: if entry.get('email to'): email_switches[entry['button mac']] = Email(entry['email to']) if found_wemos or email_switches: # FIXME: log
def dim_lights(level, room=None, light=None): target_name = room or light (target, state_get, state_set) = target_and_method_for(target_name[0]) method(target, dim=int(level)) @app.route('/lights/<action>') def light_control(action): method = None if action == 'turn_on': method = turn_lights_on elif action == 'turn_off': method = turn_lights_off elif action == 'dim': method = dim_lights if method is not None: method(**request.args) return "OK" else: return "Invalid action." if __name__ == '__main__': env.start() env.discover() bridge = env.get_bridge('WeMo Link') app.run(host='0.0.0.0')
hue = fauxhue("Fauxhue", u, p, None, 0) bulbstate = lazylights.get_state(bulbs) for bulb in bulbstate: bulbname = str(bulb.label) bulbname = bulbname.rstrip('\x00') hue.add_bulb(bulbname, state=bool(bulb.power), brightness=(255 * bulb.brightness / 255), action_handler=lifx_api_handler(), private=bulb) env = Environment() env.start() env.discover(10) for bridgename in env.list_bridges(): bridge = env.get_bridge(bridgename) if len(bridge.Lights) > 0 and hue == None: hue = fauxhue("Fauxhue", u, p, None, 0) for lightname in bridge.Lights.keys(): light = bridge.Lights[lightname] lightdata = {'bridge': bridge, 'light': lightname} state = bridge.light_get_state(light) hue.add_bulb(lightname, state=bool(state['state']), brightness=state['dim'], private=lightdata, action_handler=wemo_api_handler()) dbg("Entering main loop\n") while True:
(target, state_get, state_set) = target_and_method_for(target_name[0]) method(target, state=0) def dim_lights(level, room=None, light=None): target_name = room or light (target, state_get, state_set) = target_and_method_for(target_name[0]) method(target, dim=int(level)) @app.route('/lights/<action>') def light_control(action): method = None if action == 'turn_on': method = turn_lights_on elif action == 'turn_off': method = turn_lights_off elif action == 'dim': method = dim_lights if method is not None: method(**request.args) return "OK" else: return "Invalid action." if __name__ == '__main__': env.start() env.discover() bridge = env.get_bridge('WeMo Link') app.run(host='0.0.0.0')