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

31 lines
597 B
Python
Raw Normal View History

from gpiozero import LED
import shelve
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"]
def unlock():
led.on()
state(True)
def lock():
led.off()
state(False)
def switch():
if state():
lock()
else:
unlock()