From dea22875e61effd53bd391735cda9c9e60eaf1c0 Mon Sep 17 00:00:00 2001 From: flifloo Date: Sat, 20 Apr 2019 21:57:08 +0200 Subject: [PATCH] Forget to commit to master the lock >.> --- lock.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lock.py diff --git a/lock.py b/lock.py new file mode 100644 index 0000000..455787d --- /dev/null +++ b/lock.py @@ -0,0 +1,27 @@ +from gpiozero import LED +import shelve + +led = LED(17) + +def state(current : bool = None): + if current != None: + with shelve.open("Settings.conf") as settings: + settings["state"] = current + else: + with shelve.open("Settings.conf") as settings: + return settings["state"] + + +def unlock(): + led.on() + state(True) + +def lock(): + led.off() + state(False) + +def switch(): + if state(): + lock() + else: + unlock()