-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpylightify.py
70 lines (62 loc) · 2.31 KB
/
pylightify.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import requests
import json
import re
def _url(path):
return 'https://eu.lightify-api.org/lightify/services' + path
def post_gettoken(username, password, serialnumber):
headers = {'content-type': 'application/json'}
payload = {"username": username, "password": password, "serialNumber": serialnumber}
resp = requests.post(url=_url('/session'), json=payload, headers=headers)
gettoken_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return gettoken_dict['securityToken']
else:
return "ERROR" + str(resp.status_code)
def get_devices(at):
headers = {'Authorization': at}
resp = requests.get(_url('/devices'), headers=headers)
devices_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return devices_dict
else:
return "ERROR" + str(resp.status_code)
def get_turngroupon(at, groupid):
headers = {'Authorization': at}
resp = requests.get(_url('/group/set?idx=' + groupid + '&onoff=1'), headers=headers)
resp_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return resp_dict
else:
return "ERROR" + str(resp.status_code)
def get_turngroupoff(at, groupid):
headers = {'Authorization': at}
resp = requests.get(_url('/group/set?idx=' + groupid + '&onoff=0'), headers=headers)
resp_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return resp_dict
else:
return "ERROR" + str(resp.status_code)
def get_turnallon(at):
headers = {'Authorization': at}
resp = requests.get(_url('/device/all/set?onoff=1'), headers=headers)
resp_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return resp_dict
else:
return "ERROR" + str(resp.status_code)
def get_turnalloff(at):
headers = {'Authorization': at}
resp = requests.get(_url('/device/all/set?onoff=0'), headers=headers)
resp_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return resp_dict
else:
return "ERROR" + str(resp.status_code)
def get_apiversion(at):
headers = {'Authorization': at}
resp = requests.get(_url('/version'), headers=headers)
resp_dict = json.loads(resp.text)
if str(resp.status_code) == "200":
return resp_dict
else:
return "ERROR" + str(resp.status_code)