From 2581cc6af7b4778745e5ad4741ceaa9f5308b156 Mon Sep 17 00:00:00 2001 From: Jack Kingsman Date: Mon, 2 Mar 2026 11:46:40 -0800 Subject: [PATCH] Show error toast on PK export failure --- app/community_mqtt.py | 24 ++++++++++++++++++++++++ app/mqtt_base.py | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/app/community_mqtt.py b/app/community_mqtt.py index 2cfdb8e..63a85e4 100644 --- a/app/community_mqtt.py +++ b/app/community_mqtt.py @@ -270,6 +270,30 @@ class CommunityMqttPublisher(BaseMqttPublisher): _log_prefix = "Community MQTT" _not_configured_timeout: float | None = 30 + def __init__(self) -> None: + super().__init__() + self._key_unavailable_warned: bool = False + + async def start(self, settings: AppSettings) -> None: + self._key_unavailable_warned = False + await super().start(settings) + + def _on_not_configured(self) -> None: + from app.keystore import has_private_key + from app.websocket import broadcast_error + + if ( + self._settings + and self._settings.community_mqtt_enabled + and not has_private_key() + and not self._key_unavailable_warned + ): + broadcast_error( + "Community MQTT unavailable", + "Radio firmware does not support private key export.", + ) + self._key_unavailable_warned = True + def _is_configured(self) -> bool: """Check if community MQTT is enabled and keys are available.""" from app.keystore import has_private_key diff --git a/app/mqtt_base.py b/app/mqtt_base.py index e0e45ee..9b065da 100644 --- a/app/mqtt_base.py +++ b/app/mqtt_base.py @@ -120,6 +120,10 @@ class BaseMqttPublisher(ABC): """Called before connecting. Return True to proceed, False to retry.""" return True + def _on_not_configured(self) -> None: + """Called each time the loop finds the publisher not configured.""" + return # no-op by default; subclasses may override + # ── Connection loop ──────────────────────────────────────────────── async def _connection_loop(self) -> None: @@ -130,6 +134,7 @@ class BaseMqttPublisher(ABC): while True: if not self._is_configured(): + self._on_not_configured() self.connected = False self._client = None self._version_event.clear()