forked from tlyakhov/python-decora_wifi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-test.py
executable file
·56 lines (47 loc) · 1.69 KB
/
cli-test.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python
from decora_wifi import DecoraWiFiSession
from decora_wifi.models.person import Person
from decora_wifi.models.residential_account import ResidentialAccount
from decora_wifi.models.residence import Residence
import sys
if len(sys.argv) < 4:
print('Usage: ./cli-test.py [email] [pass] [ON|OFF] [BRIGHTNESS 0-100]')
decora_email = sys.argv[1]
decora_pass = sys.argv[2]
decora_cmd = sys.argv[3]
if len(sys.argv) >= 5:
decora_bright = int(sys.argv[4])
else:
decora_bright = None
session = DecoraWiFiSession()
session.login(decora_email, decora_pass)
# Gather all the available devices...
perms = session.user.get_residential_permissions()
print('{} premissions'.format(len(perms)))
all_residences = []
for permission in perms:
print("Permission: {}".format(permission))
if permission.residentialAccountId is not None:
acct = ResidentialAccount(session, permission.residentialAccountId)
for res in acct.get_residences():
print("Residence: {}".format(res))
all_residences.append(res)
elif permission.residenceId is not None:
res = Residence(session, permission.residenceId)
print("Residence: {}".format(res))
all_residences.append(res)
all_switches = []
for residence in all_residences:
for switch in residence.get_iot_switches():
print("Switch: {}".format(switch))
attribs = {}
if decora_bright is not None:
attribs['brightness'] = decora_bright
if decora_cmd == 'ON':
print('ON!')
attribs['power'] = 'ON'
else:
print('OFF!')
attribs['power'] = 'OFF'
switch.update_attributes(attribs)
Person.logout(session)