diff --git a/CHANGELOG.md b/CHANGELOG.md index 544c6b1..41144b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [0.8.7] - 2026-02-19 + +### Fixed +- **Startup-Warning "connection.established missed"** (fixes #2): Der Fallback-Check + nach `TCPInterface()`-Konstruktor prüfte `_connected` sofort, obwohl das Event + `connection.established` erst kurz danach aus dem Bibliotheks-Thread feuert. + Fix: `threading.Event` wartet jetzt bis zu 10 Sekunden auf das Event; der Fallback + greift nur noch bei echtem Ausbleiben des Events. + ## [0.8.6] - 2026-02-19 ### Added diff --git a/config.yaml b/config.yaml index 0826f7f..adffdbc 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,4 @@ -version: "0.8.6" +version: "0.8.7" bot: name: "MeshDD-Bot" diff --git a/meshbot/bot.py b/meshbot/bot.py index c3785c2..f450d92 100644 --- a/meshbot/bot.py +++ b/meshbot/bot.py @@ -1,5 +1,6 @@ import asyncio import logging +import threading import time import json import urllib.request @@ -22,6 +23,7 @@ class MeshBot: self.start_time = time.time() self.ws_manager = None # set by main.py self._connected = False + self._conn_event = threading.Event() def connect(self): host = config.get("meshtastic.host", "localhost") @@ -35,9 +37,10 @@ class MeshBot: pub.subscribe(self._on_connection_lost, "meshtastic.connection.lost") pub.subscribe(self._on_node_updated, "meshtastic.node.updated") self.interface = TCPInterface(hostname=host, portNumber=port) - # Fallback: if connection.established fired before our subscription - # was registered, set the flag and sync initial nodes manually. - if not self._connected: + # Wait up to 10 s for connection.established to fire from the library thread. + # Fallback: if the event never arrives (e.g. library behaviour change), + # initialise state manually so the bot still works. + if not self._conn_event.wait(timeout=10.0): logger.warning("connection.established missed – applying fallback") self._connected = True if self.ws_manager: @@ -161,6 +164,7 @@ class MeshBot: def _on_connection(self, interface, topic=pub.AUTO_TOPIC): logger.info("Meshtastic connection established") self._connected = True + self._conn_event.set() if self.ws_manager: self.loop.call_soon_threadsafe(asyncio.ensure_future, self._broadcast_bot_status()) if hasattr(interface, 'nodes') and interface.nodes: