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 _discover(): print('Auto-discovering Key Light ...') lights = leglight.discover(1) if not lights: print('Could not find a Key Light', file=sys.stderr) exit(1) if len(lights) > 1: print(f'Found {len(lights)} Key Lights. Using the first.') return lights[0]
def update(iofile): with open(iofile, "r") as f: lights_in_file = list(yaml.safe_load_all(f)) lights_discovered = leglight.discover(2) lights_by_name = {light.display: light for light in lights_discovered} for light in lights_in_file: name = light["name"] if name in lights_by_name: light["address"] = lights_by_name[name].address light["port"] = lights_by_name[name].port else: print("Warning, light {} not detected. Leaving it as is in file.". format(name)) with open(iofile, "w") as f: yaml.dump_all(lights_in_file, f)
def discover_lights(self): lights_before = len(self.all_lights) if time.time() - self.last_light_discover > 60: logging.debug("Starting to discover lights...") try: self.all_lights = leglight.discover(2) self.last_light_discover = time.time() if lights_before != len(self.all_lights): logging.info("Found %s Elgato lights:" % len(self.all_lights)) for light in self.all_lights: logging.info(" %s" % light) except OSError as err: self.last_light_discover = time.time() - 30 logging.error("OS error: {0}".format(err))
import leglight allLights = leglight.discover(2) print(allLights)
def scan(): for l in leglight.discover(2): print("💡" + l.display)
#!/usr/bin/env python import leglight import os import time import sys light = None light_name = os.environ.get("SUNLAMPNAME") if light_name is None: print("⚠️ Please set environment variable SUNLAMPNAME.") print("ℹ️ Use the 'scan' command to scan for available lamp names.") else: for l in leglight.discover(2): if l.display == light_name: light = l if light is None: print("⚠️ Sorry, I could not find a light named {}.".format(light_name)) else: print("💡Detected {}.".format(light)) # First element = brightness (range: 0-100) # Second element = temperature (range: 2900-7000) day = (90, 6000) night = (1, 3000) # (hour,minute) sunrise_begin = (7, 0)
def save(outfile): lights = leglight.discover(2) for light in lights: print(template.format(**light.__dict__), file=outfile)