src.nth.io/

summaryrefslogtreecommitdiff
path: root/roles/hap-nodejs/files/doord.py
diff options
context:
space:
mode:
authorLuke Hoersten <[email protected]>2018-01-19 11:54:24 -0600
committerLuke Hoersten <[email protected]>2018-01-19 11:54:24 -0600
commit485592bf0a22d7fbdcad6526e36b97e363aef81c (patch)
tree175ef1d9f16ee00718d93a5222e012893a1450b3 /roles/hap-nodejs/files/doord.py
parent5f6b0c0e6e2ea3621cb0033b9f5498372c89db74 (diff)
Pulled out src files.
Diffstat (limited to 'roles/hap-nodejs/files/doord.py')
-rwxr-xr-xroles/hap-nodejs/files/doord.py51
1 files changed, 0 insertions, 51 deletions
diff --git a/roles/hap-nodejs/files/doord.py b/roles/hap-nodejs/files/doord.py
deleted file mode 100755
index 4cde487..0000000
--- a/roles/hap-nodejs/files/doord.py
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/env python3
-
-import time
-import automationhat
-import sys
-
-import queue
-import threading
-
-
-def main():
- command_queue = queue.LifoQueue()
- read_thread = threading.Thread(target=read_loop, args=[command_queue])
- read_thread.start()
- run_loop(command_queue)
-
-
-def read_loop(command_queue):
- while True:
- command_queue.put_nowait(sys.stdin.readline().rstrip('\n'))
-
-
-def run_loop(command_queue):
- thread_local = threading.local()
- thread_local.doorbell_on_state = False
-
- while True:
- run_command(command_queue)
- read_doorbell(thread_local)
-
-
-def run_command(command_queue):
- try:
- command = command_queue.get(timeout=0.5)
- except queue.Empty:
- pass
- else:
- automationhat.relay.on() if command == "unlock" else automationhat.relay.off()
-
-
-def read_doorbell(thread_local):
- analog_value = automationhat.analog.one.read()
- doorbell_on_state = 6.0 < analog_value and analog_value < 6.3
-
- if doorbell_on_state != thread_local.doorbell_on_state:
- thread_local.doorbell_on_state = doorbell_on_state
- print("doorbell_on") if doorbell_on_state else print("doorbell_off")
-
-
-if __name__ == "__main__":
- main()