format with ruff

This commit is contained in:
2026-05-03 14:25:53 -04:00
parent 11a6abdf10
commit 6ac11cb4a8
3 changed files with 161 additions and 115 deletions
+61 -59
View File
@@ -5,75 +5,77 @@ import json
GOVEE_API_BASE_URL = "https://openapi.api.govee.com/router/api/v1/"
class GoveeApi:
key = ""
headers = {}
key = ""
headers = {}
def __init__(self, key):
self.key = key
self.headers = {
'Govee-API-Key': key
}
def __init__(self, key):
self.key = key
self.headers = {"Govee-API-Key": key}
def __get_random_string(self):
characters = string.ascii_letters + string.digits
result_str = ''.join(random.choices(characters, k=4))
return result_str
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):
payload = {
"requestId": self.__get_random_string(),
"payload": {
"sku": sku,
"device": device
}
}
res = requests.post(GOVEE_API_BASE_URL + 'device/diy-scenes', json=payload, headers=self.headers)
res.raise_for_status()
print("[GOVEE] DIY scene fetch: " + json.dumps(res.json(), indent=4))
return res.ok
def set_diy_scene(self, sku, device):
payload = {
'requestId': self.__get_random_string(),
'payload': {
'sku': sku,
'device': device,
'capability': {
'type': 'device.capabilities.dynamic_scene',
'instance': 'diyScene',
'value': 22757907
def get_diy_scenes(self, sku, device):
payload = {
"requestId": self.__get_random_string(),
"payload": {"sku": sku, "device": device},
}
}
}
res = requests.post(GOVEE_API_BASE_URL + 'device/control', headers=self.headers, json=payload)
res.raise_for_status()
res = requests.post(
GOVEE_API_BASE_URL + "device/diy-scenes", json=payload, headers=self.headers
)
res.raise_for_status()
print("[GOVEE] Set DIY scene: " + json.dumps(res.json(), indent=4))
print("[GOVEE] DIY scene fetch: " + json.dumps(res.json(), indent=4))
return res.ok
return res.ok
def set_to_original_color(self, sku, device):
payload = {
'requestId': self.__get_random_string(),
'payload': {
'sku': sku,
'device': device,
'capability': {
'type': 'devices.capabilities.color_setting',
'instance': 'colorRgb',
'value': 16711680
def set_diy_scene(self, sku, device):
payload = {
"requestId": self.__get_random_string(),
"payload": {
"sku": sku,
"device": device,
"capability": {
"type": "device.capabilities.dynamic_scene",
"instance": "diyScene",
"value": 22757907,
},
},
}
}
}
res = requests.post(GOVEE_API_BASE_URL + 'device/control', json=payload, headers=self.headers)
res.raise_for_status()
res = requests.post(
GOVEE_API_BASE_URL + "device/control", headers=self.headers, json=payload
)
res.raise_for_status()
print("[GOVEE] Set to original: " + json.dumps(res.json(), indent=4))
print("[GOVEE] Set DIY scene: " + json.dumps(res.json(), indent=4))
return res.ok
return res.ok
def set_to_original_color(self, sku, device):
payload = {
"requestId": self.__get_random_string(),
"payload": {
"sku": sku,
"device": device,
"capability": {
"type": "devices.capabilities.color_setting",
"instance": "colorRgb",
"value": 16711680,
},
},
}
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