-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwemo.py
40 lines (32 loc) · 1.07 KB
/
wemo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
import argparse
import sys
from ouimeaux.environment import Environment
from ouimeaux.utils import matcher
from ouimeaux.signals import receiver, statechange, devicefound
def mainloop(name):
matches = matcher(name)
@receiver(devicefound)
def found(sender, **kwargs):
if matches(sender.name):
print("Found device:", sender.name)
@receiver(statechange)
def motion(sender, **kwargs):
if matches(sender.name):
print("{} state is {state}".format(
sender.name, state="on" if kwargs.get('state') else "off"))
env = Environment()
try:
env.start()
env.discover(10)
env.wait()
except (KeyboardInterrupt, SystemExit):
print("Goodbye!")
sys.exit(0)
if __name__ == "__main__":
parser = argparse.ArgumentParser("Motion notifier")
parser.add_argument("name", metavar="NAME",
help="Name (fuzzy matchable)"
" of the Motion to detect")
args = parser.parse_args()
mainloop(args.name)