-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoveeAPI.py
71 lines (61 loc) · 2.16 KB
/
GoveeAPI.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
import requests
import uuid
class GoveeAPI:
def __init__(self, apiKey):
self.apiKey = apiKey
self.baseURL = 'https://openapi.api.govee.com/router/api/v1/'
self.headers = {
'Govee-API-Key': apiKey,
'Content-Type': 'application/json'
}
#retrieve all device data from account
def getDevices(self):
endpoint = "user/devices"
response = requests.get(f"{self.baseURL}{endpoint}", headers=self.headers)
print(response.json())
#enpoints for device control
def turnOff(self, model, device):
endpoint = "device/control"
data = {
"requestId": str(uuid.uuid4()),
"payload": {
"sku": model,
"device": device,
"capability": {
"type": "devices.capabilities.on_off",
"instance": "powerSwitch",
"value": 0 # 0 to turn off, 1 to turn on
}
}
}
return requests.post(f"{self.baseURL}{endpoint}", headers=self.headers, json=data)
def turnOn(self, model, device):
endpoint = "device/control"
data = {
"requestId": str(uuid.uuid4()),
"payload": {
"sku": model,
"device": device,
"capability": {
"type": "devices.capabilities.on_off",
"instance": "powerSwitch",
"value": 1 # 0 to turn off, 1 to turn on
}
}
}
return requests.post(f"{self.baseURL}{endpoint}", headers=self.headers, json=data)
def changeColor(self, model, device, setting):
endpoint = "device/control"
data = {
"requestId": str(uuid.uuid4()),
"payload": {
"sku": model,
"device": device,
"capability": {
"type": "devices.capabilities.color_setting",
"instance": "colorRgb",
"value": setting
}
}
}
return requests.post(f"{self.baseURL}{endpoint}", headers=self.headers, json=data)