Skip to content

fix(ha): emit retain as JSON boolean in discovery payloads#459

Merged
nanomad merged 2 commits into
developfrom
fix/ha-discovery-retain-bool
Jun 24, 2026
Merged

fix(ha): emit retain as JSON boolean in discovery payloads#459
nanomad merged 2 commits into
developfrom
fix/ha-discovery-retain-bool

Conversation

@nanomad

@nanomad nanomad commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

  • str(retain).lower() in HaBaseSwitch / select / number discovery methods produced Python strings "true"/"false" which json.dumps serialized as JSON strings
  • Home Assistant's MQTT discovery schema expects a boolean; the string caused schema validation to reject the retain flag
  • Command topics for number and select entities (refresh periods, target SoC) were not retained on the broker, so gateway settings were lost after every HA restart
  • Fix: pass retain directly — it is already a bool

Test plan

  • Existing test_discovery_retain.py tests updated to assert True/False instead of "true"/"false" — all 293 tests pass
  • Manual: verify HA number/select entities retain their values after broker restart

nanomad added 2 commits June 24, 2026 23:01
str(retain).lower() produced the Python strings "true"/"false" which
json.dumps serialized as JSON strings. Home Assistant's MQTT discovery
schema expects a boolean; the string caused schema validation to reject
the retain flag, so command topics for number/select entities were not
retained on the broker and gateway settings were lost after an HA restart.
@nanomad nanomad merged commit cdeb882 into develop Jun 24, 2026
6 checks passed
@nanomad nanomad deleted the fix/ha-discovery-retain-bool branch June 24, 2026 21:02
@nanomad nanomad mentioned this pull request Jun 24, 2026
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