-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsonoff-req
executable file
·40 lines (35 loc) · 973 Bytes
/
sonoff-req
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/python
import argparse
from sonoffreq import Sonoff
parser = argparse.ArgumentParser()
options = parser.add_argument_group('OPTIONS')
state = parser.add_argument_group('STATE')
options.add_argument(
'--addr', '-a',
metavar='IP',
help='ip address of a sonoff on your local network',
required=True,
)
options.add_argument(
'--port', '-p',
metavar='PORT',
default=8081,
help='Port of the webserver running in the sonoff (default: 8081)',
)
options.add_argument(
'--api-key', '-k',
metavar='KEY',
help='API key. If you don\'t know how to obtain this, take a look at: ' +
'https://pysonofflanr3.readthedocs.io/encryption.html#obtaining-the-api-key',
required=True,
)
state.add_argument(
'state',
nargs='?',
choices=['on', 'off'],
default='on',
help='State to switch the device (default: on)',
)
args = parser.parse_args()
s = Sonoff(args.addr, args.api_key, args.port)
s.switch(args.state)