def load(infile): lights = yaml.safe_load_all(infile) for light in lights: l = leglight.LegLight(light["address"], light["port"]) l.brightness(light["brightness"]) l.color(light["temperature"]) l.on() if light["power"] else l.off()
def refresh(self) -> None: """Discover the lights on the network.""" lights = leglight.discover(5) self.lights = [ leglight.LegLight(light.address, light.port) for light in lights ] self.save()
def set_ip(value): global light ip_address = ip_entry_fld.get() try: light = leglight.LegLight(ip_address, 9123) btn['state'] = 'disabled' btn['text'] = 'Connected' print("Connected") except: messagebox.showerror("Error", "Not able to connect")
def hydrate(self) -> None: """Hydrate with light data from the config file.""" with open(self.path) as f: lights: List[DiscoveredLight] = json.loads(f.read()) ok = True for (i, light) in enumerate(lights): try: self.lights.append( leglight.LegLight(light["address"], light["port"])) except requests.exceptions.Timeout: print( f"Light {i} ({light['address']}:{light['port']}) " "could not be found", file=sys.stderr, ) ok = False if not ok: print("You may want to run light discovery again " "(`elgato lights --discover`)")
#!/bin/python import leglight import argparse parser = argparse.ArgumentParser() parser.add_argument("--on", action="store_true", help="Turn the light on") parser.add_argument("--off", action="store_true", help="Turn the light off") args = parser.parse_args() myLight = leglight.LegLight('192.168.5.25', 9123) if args.on: myLight.brightness(5) myLight.on() elif args.off: myLight.off() #myLight.on() #myLight.brightness(14) #myLight.color(3500)
def _connect(host, port): return leglight.LegLight(host, port)
import leglight myLight = leglight.LegLight('192.168.1.203', 9123) myLight.off()