fix(observer): don't log deliberate client teardown as a lost connection

Reload/stop tears old MQTT clients down on purpose; the disconnect
callback was logging 'lost connection ... auto-reconnecting' and
recording last_error for every config save. Mark clients as stopping
before teardown and return early in the callback.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2026-07-14 19:48:28 +02:00
parent 79ee58d91a
commit ca44acab7f
+3
View File
@@ -311,6 +311,7 @@ class ObserverManager:
def _stop_clients(self, clients, publish_offline=True):
for ci in clients:
client = ci['client']
ci['stopping'] = True # silence the disconnect callback for this teardown
try:
if publish_offline and client.is_connected():
msg = client.publish(ci['status_topic'],
@@ -458,6 +459,8 @@ class ObserverManager:
def _on_disconnect_cb(self, client, userdata, disconnect_flags, reason_code,
properties=None):
userdata['connected'] = False
if userdata.get('stopping'):
return # deliberate teardown (reload/stop), not a lost connection
reason = str(reason_code)
if reason not in ('Success', '0'):
userdata['last_error'] = reason