class NanoleafController(BaseController): """ This class controls the Nanoleaf lights """ receiving_events = False touch_event_dict = { 0: 'push', 2: 'up', 3: 'down', 4: 'left', 5: 'right', } def __init__(self): super(NanoleafController, self).__init__() self.device = Nanoleaf(ip=config.globals.devices.nanoleaf.ip, auth_token=os.environ["nanoleaf_token"]) logger.info("Nanoleaf controller has been properly set-up") self.events = [] def get_scene(self): return self.device.get_current_effect() def set_scene(self, scene): self.device.set_effect(scene) def power_off(self): self.device.power_off() def power_on(self): self.device.power_on() def add_touch_event_listener(self): self.receiving_events = True self.device.register_event(self.store_event(), event_types=[4]) def store_event(self): def register_event(event): self.events.append(event) return register_event
from nanoleafapi import discovery, Nanoleaf from nanoleafapi import RED, ORANGE, YELLOW, GREEN, LIGHT_BLUE, BLUE, LIGHT_BLUE, PINK, PURPLE, WHITE from flask import Flask app = Flask(__name__) auth_token = "yD3RlM2LKIBAUJXxILjnjeBIKtxLGroB" ip = "192.168.3.34" nl = Nanoleaf(ip, auth_token) #nl.set_color(PURPLE) #nl.set_color((210,105,30)) x = nl.list_effects() print (x) effects = ['Color Burst', 'Falling Whites', 'Fireworks', 'Flames', 'Forest', 'Inner Peace', 'Meteor Shower', 'Nemo', 'Northern Lights', 'Paint Splatter', 'Pulse PopBeats', 'Radial Sound Bar', 'Rhythmic Northern Lights', 'Romantic', 'Sound Bar', 'Streaking Notes'] nl.set_effect(effects[0]) y = nl.get_current_effect() print (y)
def activated_light_scene(): global last_light_scene nl = Nanoleaf(device_ip, auth_key) last_light_scene = nl.get_current_effect() nl.set_effect(scene_on)