From 92a88cae22658931eeeb3acfcae92ceb96690fdc Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 23 Mar 2026 21:51:34 +0100 Subject: [PATCH] fix: persist channel secrets to DB at startup for pkt_payload computation _load_channel_secrets() cached secrets in memory only. After dfc3b14 switched /api/messages to use DB channels instead of device calls, the empty channels table caused Route info and Analyzer links to disappear from message bubbles. Now upserts each channel (name + secret) to DB during startup so the API can compute pkt_payload without hitting the device. Co-Authored-By: Claude Opus 4.6 --- app/device_manager.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/device_manager.py b/app/device_manager.py index f024399..f37a398 100644 --- a/app/device_manager.py +++ b/app/device_manager.py @@ -227,7 +227,7 @@ class DeviceManager: self._connected = False async def _load_channel_secrets(self): - """Load channel secrets from device for pkt_payload computation.""" + """Load channel secrets from device for pkt_payload computation and persist to DB.""" consecutive_empty = 0 try: for idx in range(self._max_channels): @@ -243,8 +243,17 @@ class DeviceManager: secret = data.get('channel_secret', data.get('secret', b'')) if isinstance(secret, bytes): secret = secret.hex() + name = data.get('channel_name', data.get('name', '')) + if isinstance(name, str): + name = name.strip('\x00').strip() if secret and len(secret) == 32: self._channel_secrets[idx] = secret + # Persist to DB so API endpoints can read without device calls + self.db.upsert_channel(idx, name or f'Channel {idx}', secret) + consecutive_empty = 0 + elif name: + # Channel exists but has no secret (e.g. Public) + self.db.upsert_channel(idx, name, None) consecutive_empty = 0 else: consecutive_empty += 1