summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2014-05-06 04:42:21 +0200
committerChristian Franke <nobody@nowhere.ws>2014-05-06 04:42:21 +0200
commiteb4fd3504f63e665166d6a76eeaa79f687430877 (patch)
treea64ba4afa0595ba5098ab642f0b181d2bc292be2
parent30e51bd0f164bc2ed82fd7ca17affc268fc1174a (diff)
doorwatch: do edge triggering in both directions
-rw-r--r--doorwatch.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/doorwatch.py b/doorwatch.py
index 1e83848..b45a1c2 100644
--- a/doorwatch.py
+++ b/doorwatch.py
@@ -12,7 +12,7 @@ import time
if __name__ == '__main__':
workdir = os.path.realpath(os.path.dirname(__file__))
- was_closed = False # Only react to changes
+ was_closed = None # Only react to changes
last_ref = None
while True:
@@ -37,9 +37,10 @@ if __name__ == '__main__':
data = data['data']
closed = data['door.left']['value']
- if was_closed and not closed:
- print "Door has been opened!"
- subprocess.call(['paplay', '--volume=32661', os.path.join(workdir, 'doorwatch.wav')])
- if not was_closed and closed:
- print "Door has been closed."
+ if was_closed is not None:
+ if was_closed and not closed:
+ print "Door has been opened!"
+ subprocess.call(['paplay', '--volume=32661', os.path.join(workdir, 'doorwatch.wav')])
+ if not was_closed and closed:
+ print "Door has been closed."
was_closed = closed