2019-05-22 15:40:28 +02:00
|
|
|
from gpiozero import LED #OutputDevice
|
2019-05-15 16:48:27 +02:00
|
|
|
import shelve, io, requests
|
2019-04-20 21:57:08 +02:00
|
|
|
|
2019-05-22 15:40:28 +02:00
|
|
|
mac = io.open("/sys/class/net/wlan0/address").read()
|
2019-04-20 21:57:08 +02:00
|
|
|
led = LED(17)
|
2019-05-22 15:40:28 +02:00
|
|
|
#open = OutputDevice(17, initial_value = False)
|
|
|
|
#close = OutputDevice(27, initial_value = False)
|
2019-04-20 21:57:08 +02:00
|
|
|
|
|
|
|
def state(current : bool = None):
|
2019-05-15 10:03:24 +02:00
|
|
|
with shelve.open("Settings.conf") as settings:
|
|
|
|
if not "state" in settings:
|
|
|
|
settings["state"] = False
|
2019-04-20 21:57:08 +02:00
|
|
|
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):
|
2019-04-20 21:57:08 +02:00
|
|
|
led.on()
|
2019-05-22 15:40:28 +02:00
|
|
|
#close.off()
|
|
|
|
#open.on()
|
2019-04-20 21:57:08 +02:00
|
|
|
state(True)
|
2019-05-22 15:40:28 +02:00
|
|
|
r = requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=unlock&id={str(keyid)}")
|
2019-04-20 21:57:08 +02:00
|
|
|
|
2019-05-15 16:48:27 +02:00
|
|
|
def lock(keyid = None):
|
2019-05-22 15:40:28 +02:00
|
|
|
#open.off()
|
|
|
|
#close.on()
|
2019-04-20 21:57:08 +02:00
|
|
|
led.off()
|
|
|
|
state(False)
|
2019-05-22 15:40:28 +02:00
|
|
|
r = requests.get(f"http://vps.flifloo.fr:5001/logs?mac={mac}&state=lock&id={str(keyid)}")
|
2019-04-20 21:57:08 +02:00
|
|
|
|
2019-05-15 16:48:27 +02:00
|
|
|
def switch(keyid = None):
|
2019-04-20 21:57:08 +02:00
|
|
|
if state():
|
2019-05-15 16:48:27 +02:00
|
|
|
lock(keyid)
|
2019-04-20 21:57:08 +02:00
|
|
|
else:
|
2019-05-15 16:48:27 +02:00
|
|
|
unlock(keyid)
|