Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blink kelder lights on good scan #78

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions vinscant/mpfiles/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import gc
import time
import urequests as req
from umqtt.robust import MQTTClient

from lib.mfrc522 import MFRC522
import lib.term_color as tc
Expand Down Expand Up @@ -82,14 +83,17 @@ def good(self, name=None):
Timer(0).init(period=500, mode=Timer.ONE_SHOT, callback=self.gotoSleep)
if name:
leddy.setText(f"Welkom {name}!")
mqtt = Mqtt()
mqtt.blink()
mqtt.close()

def error(self):
self.led.setColor(*StatusNotifier.colors[0])
self.buzzer.start(250)
self.gotoSleep()

class Leddy:
def __init__(self, address="http://10.0.2.3") -> None:
def __init__(self, address="http://leddy") -> None:
self.address = address

def _post(self, command: str):
Expand All @@ -102,11 +106,23 @@ def setText(self, text: str):
watchdog.feed()
self._post(f"Option autoResetMs {5 * 1000}")
watchdog.feed()
time.sleep(.5)
time.sleep(1)
watchdog.feed()
self._post(f"ScrollingText {text}")
watchdog.feed()

class Mqtt:
def __init__(self, name="vinscant", host="korner", port="1883") -> None:
self.client = MQTTClient(name, host, port)
self.client.connect()

def blink(self):
topic = 'zigbee2mqtt/lights/set'
payload = '{"effect": "blink"}'
self.client.publish(bytes(topic, 'utf-8'), bytes(payload, 'utf-8'))

def close(self):
self.client.disconnect()

print("Starting Vinscant...")

Expand Down Expand Up @@ -180,10 +196,10 @@ def setText(self, text: str):
watchdog.feed()
if 200 <= res.status_code < 300:
name = res.text
print(f"vingo: {tc.GREEN}{name}{tc.RESET}")
print(f"vingo: {res.status_code} {tc.GREEN}{name}{tc.RESET}")
notifier.good(name)
else:
print(f"vingo: {tc.YELLOW}{res.text}{tc.RESET}")
print(f"vingo: {res.status_code} {tc.YELLOW}{res.text}{tc.RESET}")
notifier.error()
res.close() # does not support with statements

Expand Down
Loading