diff --git a/flux_led/__init__.py b/flux_led/__init__.py index 53cb65de..8b7650ee 100755 --- a/flux_led/__init__.py +++ b/flux_led/__init__.py @@ -450,6 +450,8 @@ def __init__(self, ipaddr, port=5577, timeout=5): self.port = port self.timeout = timeout + self.protocol = None + self.raw_state = None self._is_on = False self._mode = None @@ -457,7 +459,7 @@ def __init__(self, ipaddr, port=5577, timeout=5): self._warm_white = 0 self._cold_white = 0 self._brightness = 0 - self._socket = None + self._socket = None self._lock = threading.Lock() self.connect(2) @@ -588,7 +590,7 @@ def __str__(self): mode_str = "Unknown mode 0x{:x}".format(pattern) if pattern == 0x62: mode_str += " (tmp)" - mode_str += " raw state: " + mode_str += " raw state: " for _r in rx: mode_str += str(_r) + "," return "{} [{}]".format(power_str, mode_str) @@ -636,6 +638,10 @@ def setWarmWhite255(self, level, persist=True, retry=2): msg.append(0x00) msg.append(0x00) msg.append(int(level)) + + if self.protocol == "LEDENET": + msg.append(int(level)) + msg.append(0x0f) msg.append(0x0f) try: @@ -665,6 +671,10 @@ def setRgbw(self, r,g,b,w, persist=True, brightness=None, retry=2): msg.append(int(g)) msg.append(int(b)) msg.append(int(w)) + + if self.protocol == "LEDENET": + msg.append(0x00) + msg.append(0x0f) msg.append(0x0f) try: @@ -692,6 +702,10 @@ def setRgb(self, r,g,b, persist=True, brightness=None, retry=2): msg.append(int(r)) msg.append(int(g)) msg.append(int(b)) + + if self.protocol == "LEDENET": + msg.append(0x00) + msg.append(0x00) msg.append(0xf0) msg.append(0x0f) @@ -770,6 +784,9 @@ def setClock(self): msg.append(0x0f) self._send_msg(msg) + def setProtocol(self, protocol): + self.protocol = protocol.upper() + def setPresetPattern(self, pattern, speed): PresetPattern.valtostr(pattern) @@ -1290,6 +1307,9 @@ def parseArgs(): "and other mode specific settings. Use --timerhelp for more details.") + parser.add_option("--protocol", dest="protocol", default=None, metavar="PROTOCOL", + help="Set the device protocol. Currently only supports LEDENET") + other_group.add_option("-v", "--volatile", action="store_true", dest="volatile", default=False, help="Don't persist mode setting with hard power cycle (RGB and WW modes only).") @@ -1400,6 +1420,7 @@ def main(): info = dict() info['ipaddr'] = addr info['id'] = 'Unknown ID' + bulb_info_list.append(info) @@ -1417,6 +1438,9 @@ def main(): if options.setclock: bulb.setClock() + if options.protocol: + bulb.setProtocol(options.protocol) + if options.ww is not None: print("Setting warm white mode, level: {}%".format(options.ww)) bulb.setWarmWhite(options.ww, not options.volatile)