From 481b3c7194a20750ae57d755a838c37940b2099c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Fri, 1 Jul 2022 22:28:36 +0200 Subject: [PATCH] removed publishes in unescafrejhkjogitrj MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 8b91925..5b93909 100644 --- a/main.py +++ b/main.py @@ -168,6 +168,7 @@ if __name__ == '__main__': mode = 0 power = "True" + threading.Thread(target=lambda: app.run(host='0.0.0.0', port=80)).start() mqttBroker ="homeassistant.ping-mee.local" @@ -177,6 +178,9 @@ if __name__ == '__main__': client.connect(mqttBroker) client.on_connect = mqtt_on_connect + client.publish("server-rack-led-1/power","True") + client.publish("server-rack-led-1/mode","0") + def mqtt_on_message(client, userdata, msg): print(f"Message received [{msg.topic}]: {msg.payload}") if str(msg.topic) == "server-rack-led-1/power": @@ -203,22 +207,17 @@ if __name__ == '__main__': try: while True: if power == "True": - client.publish("server-rack-led-1/power","True") - if mode == 0: - client.publish("server-rack-led-1/mode","0") rainbowCycle(strip) + elif mode == 1: - client.publish("server-rack-led-1/mode","1") - client.publish("server-rack-led-1/r",str(r)) - client.publish("server-rack-led-1/g",str(g)) - client.publish("server-rack-led-1/b",str(b)) setColor(strip, Color(int(r), int(g), int(b))) time.sleep(1) else: client.publish("server-rack-led-1/power","False") setColor(strip, Color(0,0,0)) time.sleep(1) + except KeyboardInterrupt: client.disconnect() setColor(strip, Color(0,0,0))