house cleaning

This commit is contained in:
2026-05-03 03:27:57 -04:00
parent 920e11acdf
commit ba47ae0952
10 changed files with 209809 additions and 170 deletions
+24 -21
View File
@@ -6,37 +6,37 @@ import json
GOVEE_API_BASE_URL = "https://openapi.api.govee.com/router/api/v1/"
class GoveeApi:
device_ip = ""
key = ""
headers = {}
def __init__(self, key):
self.key = key
self.headers = {
'Govee-API-Key': key
}
def get_random_string(self):
# Choose from all lowercase, uppercase letters, and digits
def __get_random_string(self):
characters = string.ascii_letters + string.digits
result_str = ''.join(random.choices(characters, k=4))
return result_str
def get_diy_scenes(self, sku, device):
headers = {
'Govee-API-Key': self.key
}
payload = {
"requestId": self.get_random_string(),
"requestId": self.__get_random_string(),
"payload": {
"sku": sku,
"device": device
}
}
res = requests.post(GOVEE_API_BASE_URL + 'device/diy-scenes', json=payload, headers=headers)
res = requests.post(GOVEE_API_BASE_URL + 'device/diy-scenes', json=payload, headers=self.headers)
res.raise_for_status()
print(json.dumps(res.json(), indent=4))
print("[GOVEE] DIY scene fetch: " + json.dumps(res.json(), indent=4))
return res.ok
def set_diy_scene(self, sku, device):
headers = {
'Govee-API-Key': self.key
}
payload = {
'requestId': self.get_random_string(),
'payload': {
@@ -50,15 +50,14 @@ class GoveeApi:
}
}
print(json.dumps(payload, indent=4))
req = requests.post(GOVEE_API_BASE_URL + 'device/control', headers=headers, json=payload)
req.raise_for_status()
print(req.json())
res = requests.post(GOVEE_API_BASE_URL + 'device/control', headers=self.headers, json=payload)
res.raise_for_status()
print("[GOVEE] Set DIY scene: " + json.dumps(res.json(), indent=4))
return res.ok
def set_to_original_color(self, sku, device):
headers = {
'Govee-API-Key': self.key
}
payload = {
'requestId': self.get_random_string(),
'payload': {
@@ -72,5 +71,9 @@ class GoveeApi:
}
}
req = requests.post(GOVEE_API_BASE_URL + 'device/control', json=payload, headers=headers)
req.raise_for_status()
res = requests.post(GOVEE_API_BASE_URL + 'device/control', json=payload, headers=self.headers)
res.raise_for_status()
print("[GOVEE] Set to original: " + json.dumps(res.json(), indent=4))
return res.ok