diff --git a/pkgs/wordclock-dimmer/wordclock-dimmer.py b/pkgs/wordclock-dimmer/wordclock-dimmer.py index 91ed437..0eccaa2 100755 --- a/pkgs/wordclock-dimmer/wordclock-dimmer.py +++ b/pkgs/wordclock-dimmer/wordclock-dimmer.py @@ -61,15 +61,6 @@ def get_color_for_time(time: datetime.time, base=(60, 60, 60)) -> (int, int, int ) -def update(client: mqtt.Client): - time = datetime.datetime.now().time() - color = get_color_for_time(time) - print(f"{time}: setting color to {color}") - sys.stdout.flush() - set_color(client, *color) - pass - - client = mqtt.Client("wordclock.py") user = os.environ["WORDCLOCK_MQTT_USER"] @@ -83,6 +74,15 @@ host = os.environ["WORDCLOCK_MQTT_HOST"] client.username_pw_set(user, password) client.connect(host, 1883, 60) +color = (0, 0, 0) + while True: - update(client) + time = datetime.datetime.now().time() + new_color = get_color_for_time(time) + if new_color != color: + color = new_color + print(f"setting color to {color}") + sys.stdout.flush() + set_color(client, *color) + sleep(300)