36 lines
987 B
Python
36 lines
987 B
Python
|
|
import paho.mqtt.client as mqttClient
|
|
import paho.mqtt.publish as publish
|
|
|
|
from sqlmodel import select
|
|
|
|
from app.services.database import Session, get_session, Depends
|
|
from app.model.models import *
|
|
|
|
doorIsOpen = True
|
|
client = mqttClient.Client(client_id="", userdata=None, protocol=mqttClient.MQTTv5)
|
|
client.tls_set(tls_version=mqttClient.ssl.PROTOCOL_TLS)
|
|
client.username_pw_set("username", "passwort")
|
|
#client.connect("host", port=8883)
|
|
# I think this could also be gpio controlled
|
|
#See: https://github.com/technyon/nuki_hub#gpio-lock-control-optional
|
|
|
|
def openDoor():
|
|
doorIsOpen = True
|
|
publish.single(topic="/lock/action", payload="unlock")
|
|
pass
|
|
|
|
def closeDoor():
|
|
doorIsOpen = False
|
|
publish.single(topic="/lock/action", payload="lock")
|
|
pass
|
|
|
|
def isDoorOpen():
|
|
return doorIsOpen
|
|
|
|
def checkAccess(uuid: str, db: Session = Depends(get_session)):
|
|
card = db.exec(select(Card).where(Card.uuid == uuid)).one()
|
|
print(card.group.accessauths.timetables)
|
|
|
|
|