From 44b4277b8edfdc2ad9e067cc728cd76b93ad5d07 Mon Sep 17 00:00:00 2001 From: space Date: Sun, 1 Mar 2026 15:11:24 +0100 Subject: [PATCH] feat: refactor state management to use Redis instead of file storage --- functions/control/main.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/functions/control/main.py b/functions/control/main.py index 76b7522..c376069 100644 --- a/functions/control/main.py +++ b/functions/control/main.py @@ -30,16 +30,19 @@ MINIO_CLIENT = Minio( ) BUCKET = "tv-control" r = redis.Redis(host='194.15.36.205',username="default", port=12004, db=12, password=os.getenv("REDIS")) + def _read_state(): - try: - with open("/app/state.json", "r") as f: - return json.load(f) - except (FileNotFoundError, json.JSONDecodeError): + state_json = r.get("tv-control-state") + if state_json: + try: + return json.loads(state_json) + except json.JSONDecodeError: + return dict(DEFAULT_STATE) + else: return dict(DEFAULT_STATE) def _write_state(state): - with open("/app/state.json", "w") as f: - json.dump(state, f) + r.set("tv-control-state", json.dumps(state)) def main(args): route = args.get("route")