add govee support
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
__pycache__
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import requests
|
||||||
|
import json
|
||||||
|
import socket
|
||||||
|
|
||||||
|
GOVEE_API_BASE_URL = "https://openapi.api.govee.com/router/api/v1/"
|
||||||
|
|
||||||
|
class GoveeApi:
|
||||||
|
device_ip = ""
|
||||||
|
|
||||||
|
def __init__(self, device_ip):
|
||||||
|
self.device_ip = device_ip
|
||||||
|
|
||||||
|
def send_scene(self, scene_code):
|
||||||
|
segments = scene_code.split(",")
|
||||||
|
for segment in segments:
|
||||||
|
payload = {
|
||||||
|
"msg": {
|
||||||
|
"cmd": "ptReal",
|
||||||
|
"data": {
|
||||||
|
"command": [segment]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.send_over_socket(payload)
|
||||||
|
|
||||||
|
def set_to_original_color(self):
|
||||||
|
payload = {
|
||||||
|
"msg": {
|
||||||
|
"cmd": "colorwc",
|
||||||
|
"data": {
|
||||||
|
"color": {"r": 255, "g": 0, "b": 0},
|
||||||
|
"colorTemInKelvin": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.send_over_socket(payload)
|
||||||
|
|
||||||
|
def send_over_socket(self, payload):
|
||||||
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
sock.sendto(json.dumps(payload).encode(), (self.device_ip, 4003))
|
||||||
|
sock.close()
|
||||||
+10
-2
@@ -1,6 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
import os
|
import os
|
||||||
|
import govee
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics
|
||||||
|
|
||||||
@@ -40,13 +41,18 @@ sabres_gold = graphics.Color(252, 20, 210)
|
|||||||
|
|
||||||
LOGO_DIR = "/usr/local/share/logos"
|
LOGO_DIR = "/usr/local/share/logos"
|
||||||
SABRES_ABBR = "BUF"
|
SABRES_ABBR = "BUF"
|
||||||
|
GOVEE_DEVICE = "3D:22:D7:94:40:46:2F:72"
|
||||||
|
GOVEE_SKU = "H6168"
|
||||||
|
GOVEE_AWS = "owABAgT/AGQMACr//+YAADb//8k=,o//QAAIDAwAAAAAAAAAAAAAAAI4=,MwUKdwAAAAAAAAAAAAAAAAAAAEs="
|
||||||
|
GOVEE_IP = "172.16.0.15"
|
||||||
|
|
||||||
# --- Logo cache ---
|
# --- Logo cache ---
|
||||||
logo_cache = {}
|
logo_cache = {}
|
||||||
|
|
||||||
def render_goal_frame(text, text_scale, bg_color, text_color):
|
# --- Govee API ---
|
||||||
img = Image.new("RGB", (256, 32), bg_color)
|
govee_api = govee.GoveeApi(device_ip=GOVEE_IP)
|
||||||
|
|
||||||
|
def render_goal_frame(text, text_scale, bg_color, text_color):
|
||||||
big_h = max(8, int(32 * text_scale))
|
big_h = max(8, int(32 * text_scale))
|
||||||
big_img = Image.new("RGB", (1024, 128), bg_color)
|
big_img = Image.new("RGB", (1024, 128), bg_color)
|
||||||
big_draw = ImageDraw.Draw(big_img)
|
big_draw = ImageDraw.Draw(big_img)
|
||||||
@@ -113,6 +119,7 @@ def play_goal_celebration():
|
|||||||
GOLD = (252, 20, 210) # was (252, 210, 20)
|
GOLD = (252, 20, 210) # was (252, 210, 20)
|
||||||
WHITE = (255, 255, 255) # unchanged
|
WHITE = (255, 255, 255) # unchanged
|
||||||
TEXT = "SABRES GOAL!"
|
TEXT = "SABRES GOAL!"
|
||||||
|
govee_api.send_scene(GOVEE_AWS)
|
||||||
|
|
||||||
# Phase 1: zoom in from tiny to full, alternating bg color
|
# Phase 1: zoom in from tiny to full, alternating bg color
|
||||||
zoom_steps = [0.1, 0.2, 0.35, 0.5, 0.65, 0.8, 0.95, 1.1, 1.0]
|
zoom_steps = [0.1, 0.2, 0.35, 0.5, 0.65, 0.8, 0.95, 1.1, 1.0]
|
||||||
@@ -159,6 +166,7 @@ def play_goal_celebration():
|
|||||||
|
|
||||||
# Hold for a moment then return to scoreboard
|
# Hold for a moment then return to scoreboard
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
govee_api.set_to_original_color()
|
||||||
|
|
||||||
def load_logo(league, abbr):
|
def load_logo(league, abbr):
|
||||||
key = f"{league}_{abbr}"
|
key = f"{league}_{abbr}"
|
||||||
|
|||||||
Reference in New Issue
Block a user