Skip to content

Improve safety state reporting and MQTT reconnect availability - #118

Merged
chvvkumar merged 3 commits into
devfrom
snd
Oct 8, 2026
Merged

chvvkumar merged 3 commits into
devfrom
snd

Conversation

@chvvkumar

@chvvkumar chvvkumar commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

📋 Overview

This pull request primarily addresses two issues: inaccurate safety state reporting to external APIs and dashboards, and Home Assistant device availability problems after MQTT reconnects. It refactors the safety state logic to report the true detector state, applying client-specific gates only for Alpaca connections. Additionally, it ensures Home Assistant devices correctly show as online after an MQTT broker reconnect.

🔄 Changes by Category

  • Features:
    • External API, dashboard, and MQTT now consistently report the real, debounced safety detector state.
  • Bug Fixes:
    • Corrected IsSafe reporting for external APIs and the dashboard, which previously showed False when no ASCOM client was connected.
    • Restored Home Assistant device availability after an MQTT broker reconnect by republishing discovery configurations on every successful connection.
  • Refactoring:
    • Moved the ASCOM client connection gate for IsSafe from the shared is_safe() method to specific Alpaca issafe and devicestate routes, applying it per client.
  • Documentation:
    • Updated EXTERNAL_API.md to reflect changes in safety state reporting.
  • Tests:
    • Added new tests for the IsSafe gate logic.
    • Added new tests for MQTT reconnect availability.
    • Modified multi-client verification tests.
  • Configuration:
    • Updated .gitignore to include new entries.
    • Renamed the dashboard tile to "Safety State" and added a tooltip.

📊 Analyzed 3 commit(s) | 🕐 Updated: 2026-10-08T07:29:08.265Z | Generated by GitHub Actions


… of ASCOM connections

The driver used to force IsSafe to False whenever no ASCOM client was
connected, and that gate lived inside the shared is_safe() method, so it
leaked into /api/ext/v1/status and the dashboard too. Webhook, script and
microcontroller users of the external API therefore always saw is_safe:false
unless NINA happened to be attached (issue #117), and the dashboard appeared
frozen with no client (issue #90). MQTT had already bypassed the gate, so the
three surfaces disagreed with each other.

The gate was never an ASCOM requirement. The spec defines Connected per
client and says IsSafe raises NotConnected when not connected; it never asks
for a False value. ConformU dropped its "IsSafe must be False before connect"
check on 2025-03-16 by Core Team decision.

is_safe() now returns the debounced detector state. The Alpaca issafe and
devicestate routes apply the gate themselves, per client (IP + ClientID), so
a client that never connected still sees False exactly as before, while the
external API, dashboard and MQTT all report the same real state. The
dashboard tile is renamed Safety State with a tooltip describing the split.
Verified with ConformU 4.5 (no issues) and a local Docker run.
When the broker session dropped, the broker published the retained "offline"
Last Will for the device. paho's loop_start() then reconnected silently, but
discovery and availability were only ever published once at startup, so
nothing set the device back to "online". Home Assistant showed the cloud
detector as permanently unavailable even though its state topics kept
updating every detection cycle.

Both MQTT setup paths now install an on_connect handler that republishes the
discovery configs, which includes the retained "online" availability message,
on every successful connect rather than only the first. The handler accepts
the paho 1.x and 2.x callback shapes and ignores failed connects. The
ha_discovery attribute is initialised before the client is created because
the callback fires from the network thread and may run before discovery has
been set up; it simply no-ops in that case and the normal startup publish
covers it.
@github-actions github-actions Bot changed the title Snd Improve safety state reporting and MQTT reconnect availability Oct 8, 2026
@chvvkumar
chvvkumar merged commit beb3fb4 into dev Oct 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant