Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
smartlock/lock.py

34 lines
896 B
Python
Raw Normal View History

from gpiozero import LED
2019-05-15 16:48:27 +02:00
import shelve, io, requests
led = LED(17)
def state(current : bool = None):
with shelve.open("Settings.conf") as settings:
if not "state" in settings:
settings["state"] = False
if current != None:
with shelve.open("Settings.conf") as settings:
settings["state"] = current
else:
with shelve.open("Settings.conf") as settings:
return settings["state"]
2019-05-15 16:48:27 +02:00
def unlock(keyid = None):
led.on()
state(True)
2019-05-15 16:48:27 +02:00
mac = io.open("/sys/class/net/wlan0/address").read()
requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=unlock&id={str(keyid)}")
2019-05-15 16:48:27 +02:00
def lock(keyid = None):
led.off()
state(False)
2019-05-15 16:48:27 +02:00
requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=lock&id={str(keyid)}")
2019-05-15 16:48:27 +02:00
def switch(keyid = None):
if state():
2019-05-15 16:48:27 +02:00
lock(keyid)
else:
2019-05-15 16:48:27 +02:00
unlock(keyid)