Fix meter lifecycle and MQTT/HA integration bugs #1

Merged
adebaumann merged 8 commits from fix-attach-meters-detach into main 2026-06-26 23:53:16 +00:00
Owner

Summary

Fixes a batch of meter-lifecycle and MQTT/Home Assistant integration bugs.

  • Detach freed PWM channels in attachMeters() — channels orphaned when the meter count shrinks or a pin changes are now detached and driven low (meter reads zero) instead of left driving PWM on the old pin.
  • Clear retained HA discovery for removed meters so Home Assistant drops stale entities instead of keeping them forever.
  • Shorten MQTT probe timeout (1500 ms → 400 ms) to limit how long the blocking probe stalls the web server per reconnect attempt.
  • Allow anonymous MQTT brokers — only require a host; empty credentials are passed as NULL for an anonymous connection.
  • Wire MQTT availability into HA discovery — LWT/status now use online/offline, and discovery includes availability_topic + payloads so HA tracks online/offline state.
  • Retain HA command messages (retain: true in discovery) so commanded values survive restarts.
  • Escape < and > in escHtml to prevent stored XSS via config fields.
  • Persist MQTT settings when disabling MQTT — connection fields are saved regardless of the enable checkbox.
## Summary Fixes a batch of meter-lifecycle and MQTT/Home Assistant integration bugs. - **Detach freed PWM channels** in `attachMeters()` — channels orphaned when the meter count shrinks or a pin changes are now detached and driven low (meter reads zero) instead of left driving PWM on the old pin. - **Clear retained HA discovery** for removed meters so Home Assistant drops stale entities instead of keeping them forever. - **Shorten MQTT probe timeout** (1500 ms → 400 ms) to limit how long the blocking probe stalls the web server per reconnect attempt. - **Allow anonymous MQTT brokers** — only require a host; empty credentials are passed as `NULL` for an anonymous connection. - **Wire MQTT availability into HA discovery** — LWT/status now use `online`/`offline`, and discovery includes `availability_topic` + payloads so HA tracks online/offline state. - **Retain HA command messages** (`retain: true` in discovery) so commanded values survive restarts. - **Escape `<` and `>` in `escHtml`** to prevent stored XSS via config fields. - **Persist MQTT settings when disabling MQTT** — connection fields are saved regardless of the enable checkbox.
adebaumann added 8 commits 2026-06-26 23:52:11 +00:00
adebaumann merged commit ee73a0f9ba into main 2026-06-26 23:53:16 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adebaumann/M1730-ESP32#1