29 lines
785 B
Python
29 lines
785 B
Python
import subprocess
|
|
from tenacity import retry, stop_after_attempt
|
|
from colormap import rgb2hex
|
|
|
|
|
|
@retry(stop=stop_after_attempt(5))
|
|
def run_bulb_action(value):
|
|
result = subprocess.run(
|
|
[
|
|
f"gatttool -i hci0 -b b2:3b:03:00:14:d6 --char-write-req -a 0x0009 -n {value}"
|
|
],
|
|
stdout=subprocess.PIPE,
|
|
shell=True,
|
|
).stdout.decode("utf-8")
|
|
print(result)
|
|
if "Characteristic value was written successfully" not in result:
|
|
raise Exception
|
|
else:
|
|
return True
|
|
|
|
|
|
def convert_to_bulb_format(colour_map):
|
|
hex = rgb2hex(
|
|
colour_map["color"]["r"], colour_map["color"]["g"], colour_map["color"]["b"]
|
|
)
|
|
hex = hex.replace("#", "")
|
|
value = "56" + hex + "00f0aa"
|
|
return value
|