add govee support

This commit is contained in:
2026-05-02 22:04:15 -04:00
parent 250b04c5dc
commit 6e6719ceea
3 changed files with 52 additions and 2 deletions
+1
View File
@@ -0,0 +1 @@
__pycache__
+41
View File
@@ -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
View File
@@ -1,6 +1,7 @@
import time
import requests
import os
import govee
from PIL import Image, ImageDraw, ImageFont
from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics
@@ -40,13 +41,18 @@ sabres_gold = graphics.Color(252, 20, 210)
LOGO_DIR = "/usr/local/share/logos"
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 = {}
def render_goal_frame(text, text_scale, bg_color, text_color):
img = Image.new("RGB", (256, 32), bg_color)
# --- Govee API ---
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_img = Image.new("RGB", (1024, 128), bg_color)
big_draw = ImageDraw.Draw(big_img)
@@ -113,6 +119,7 @@ def play_goal_celebration():
GOLD = (252, 20, 210) # was (252, 210, 20)
WHITE = (255, 255, 255) # unchanged
TEXT = "SABRES GOAL!"
govee_api.send_scene(GOVEE_AWS)
# 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]
@@ -159,6 +166,7 @@ def play_goal_celebration():
# Hold for a moment then return to scoreboard
time.sleep(0.5)
govee_api.set_to_original_color()
def load_logo(league, abbr):
key = f"{league}_{abbr}"