update ui

This commit is contained in:
2026-05-17 00:04:52 +02:00
parent a285dda742
commit 9a9275dae5
26 changed files with 618 additions and 34 deletions
+13 -2
View File
@@ -106,6 +106,7 @@ def _update_env_file(updates):
# ── Internal state ────────────────────────────────────────────────────────────
_rpc_id = itertools.count(1)
_cache = {}
_cache_lock = threading.Lock()
_cava_lock = threading.Lock()
_cava_process = None
_cava_thread = None
@@ -151,7 +152,14 @@ def rpc(url, method, params=None, timeout=8):
# ── Snapcast / Mopidy metadata ────────────────────────────────────────────────
def snapcast_status():
def snapcast_status(max_age=0.75):
cache_key = ("snapcast_status", effective_snapcast_url())
now = time.time()
with _cache_lock:
cached = _cache.get(cache_key)
if cached and now - cached["at"] <= max_age:
return cached["data"]
result = rpc(effective_snapcast_url(), "Server.GetStatus")
server = result.get("server", result)
groups = server.get("groups", [])
@@ -162,12 +170,15 @@ def snapcast_status():
)
active_stream_id = active_group.get("stream_id") if active_group else None
active_stream = next((s for s in streams if s.get("id") == active_stream_id), None)
return {
data = {
"group": active_group,
"stream": active_stream,
"stream_id": active_stream_id,
"streams": streams,
}
with _cache_lock:
_cache[cache_key] = {"at": now, "data": data}
return data
def mopidy_now_playing():