update ui
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user