def update_effect(effect_name): aurora = Aurora(support.get_nanoleaf_ip(), support.get_nanoleaf_token()) aurora.on = True if effect_name == "Random\n": effect_name = aurora.effect_random() aurora.effect = effect_name return "Random - " + effect_name elif effect_name == "Flash Twice": aurora.identify() else: aurora.effect = effect_name return effect_name
def set_scene(self, scene_name): LOG.info('Attempting to set scene: ' + scene_name) MyPanels = Aurora(self.IPstring, self.tokenString) MyPanels.effect = scene_name
import json try: # Argument parsing parser = argparse.ArgumentParser("Aurora Controller") parser.add_argument("--effect") parser.add_argument("--brightness", type=int) parser.add_argument("--identify", action="store_true") parser.add_argument("--info", action="store_true") args = parser.parse_args() logger.info(args) # Connect to Aurora aurora = Aurora(IP_ADDRESS, AUTH_TOKEN) if args.brightness is not None: aurora.brightness = args.brightness if args.effect: if args.effect == "random": aurora.effect_random() else: aurora.effect = args.effect if args.identify: aurora.identify() if args.info: print(json.dumps(aurora.info, sort_keys=True, indent=4)) # Error handling except Exception as e: logger.exception(e)
from nanoleaf import Aurora import time sys.path.append('/Users/erling/Projects/') sys.path.append('/Users/erling/Projects/Yr') sys.path.append('/Users/erling/Projects/ttt') sys.path.append('/Users/erling/Projects/CryptoExchange') from weather import * from crypto_exchange import * from ttt.main import * coins = ('BTC', 'ETH', 'IOT', 'NEO') my_aurora = Aurora(IP, TOKEN) my_aurora.on = True my_aurora.effect = 'Inner Peace' def translate(value, leftMin, leftMax, rightMin, rightMax): # Figure out how 'wide' each range is leftSpan = leftMax - leftMin rightSpan = rightMax - rightMin # Convert the left range into a 0-1 range (float) valueScaled = float(value - leftMin) / float(leftSpan) # Convert the 0-1 range into a value in the right range. return rightMin + (valueScaled * rightSpan) while (True):
def nanoAction(message): global settings print(" < %s in queue" % q.qsize()) part = 1 # for Mixer and YouTube events if len(json.loads(message)["event"].split("_")) == 3: part = 2 event = json.loads(message)["event"].split("_")[part].lower() try: host = settings["nanoleaf"] token = settings["nanoleaf_token"] host2 = settings["nanoleaf2"] token2 = settings["nanoleaf2_token"] device = nl12 if event + "_device" in settings: device = settings[event + "_device"] if event == "connected": print(" + devices") if host != "": print(" o " + nl1 + " (" + host + ")") if host2 != "": print(" o " + nl2 + " (" + host2 + ")") print(" + waiting for events ...") return elif event == "naec": data = json.loads( json.loads(message, encoding='utf-8-sig')["data"]) effect_new = data["effect_new"] duration = int(data["effect_duration"]) effect_default = data["effect_default"] parameter = data["effect_parameter"] elif event == "naecupdate": readSettings() return elif settings[event + "_effect"] != '': effect_new = settings[event + "_effect"] duration = int(settings[event + "_effectduration"]) effect_default = settings["default_effect"] if (event == "host"): data = json.loads( json.loads(message, encoding='utf-8-sig')["data"]) if (int(data["viewers"]) < int( settings["host_minviewers"])): return elif (event == "cheer"): data = json.loads( json.loads(message, encoding='utf-8-sig')["data"]) if (int(data["bits"]) < int(settings["cheer_minbits"])): return else: return if (event == "host"): print(" + " + event + " (" + str(data["viewers"]) + " viewers)") elif (event == "cheer"): print(" + " + event + " (" + str(data["bits"]) + " bits)") else: print(" + " + event) print(" + actions") if host != "" and '1' in device: my_aurora = Aurora(host, token) my_aurora.on = True my_aurora.effect = effect_new else: print("no '1' in " + device) if host2 != "" and '2' in device: my_aurora2 = Aurora(host2, token2) my_aurora2.on = True my_aurora2.effect = effect_new if duration > 0: durationtext = " for " + str(duration) + " seconds" else: durationtext = "" print(" o change effect to '" + effect_new + "'" + durationtext) if duration > 0: time.sleep(duration) if host != "" and '1' in device: my_aurora.effect = effect_default if host2 != "" and '2' in device: my_aurora2.effect = effect_default print(" o change effect to '" + effect_default + "'") except KeyError: pass except ValueError: print("Could not convert data to an integer.") except: print("Unexpected error:", sys.exc_info()[0]) raise
from nanoleaf import setup from nanoleaf import Aurora from time import sleep IPaddress = '192.168.0.10' token = setup.generate_auth_token(IPaddress) myAurora = Aurora(IPaddress, token) index = 0 while index < 4: myAurora.rgb = [255,0,0] # Red sleep(1) # Red delay myAurora.rgb = [255,255,255] # White sleep(1) # White delay index = index + 1 myAurora.effect = "Flames"
#--------------------------------------- # Set Variables #--------------------------------------- path = os.path.dirname(__file__) settingsFile = "NAEC.json" settings = {} #--------------------------------------- # Get settings #--------------------------------------- try: with codecs.open(os.path.join(path, settingsFile), encoding='utf-8-sig', mode='r') as file: settings = json.load(file, encoding='utf-8-sig') print("read settings file: ", path + "\\" + settingsFile) except: print("Unexpected error:", sys.exc_info()) sys.exit("cannot read settings file") pass #--------------------------------------- # Nanoleaf Aurora actions #--------------------------------------- my_aurora = Aurora(settings["nanoleaf"], settings["nanoleaf_token"]) if len(sys.argv) > 1: my_aurora.on = True my_aurora.effect = sys.argv[1] else: my_aurora.on = False
import config from nanoleaf import Aurora from server import GSIServer from effects import bar_effect, flash_effect, fire_effect, flash nanoleafs = Aurora(config.AURORA_IP, config.AUTH_TOKEN) nanoleafs.effect = 'moonlight' server = GSIServer((config.GSI_IP, config.GSI_PORT), config.GSI_TOKEN) def on_bomb_state_changed(value): if value == 'exploded': nanoleafs.effect_set_raw(flash_effect(nanoleafs)) nanoleafs.effect = 'moonlight' nanoleafs.effect_set_raw(fire_effect()) server.gamestate.round.register(on_bomb_state_changed) server.start_server()