mqtt: expose limit-battery-charge mode in Home Assistant discovery#338
Conversation
|
Ups! |
There was a problem hiding this comment.
Pull request overview
This PR updates Home Assistant MQTT discovery for batcontrol to include the already-supported mode 8 (“Limit Battery Charge”) in the discovered select entity, and adds a regression test to ensure the discovery templates/options include that mode.
Changes:
- Add mode
8(“Limit Battery Charge”) to the MQTT discovery select’soptions,value_template, andcommand_template. - Add a regression test validating discovery includes the new mode mapping.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/batcontrol/mqtt_api.py |
Extends HA MQTT discovery templates/options to expose mode 8 in the mode select. |
tests/batcontrol/test_mqtt_api.py |
Adds a regression test asserting mode 8 is present in discovery options and templates. |
| class TestModeDiscovery: | ||
| """Mode discovery should expose the full externally supported mode model.""" | ||
|
|
There was a problem hiding this comment.
The new discovery-related tests make this module-level scope broader than the current file docstring (which says it focuses on _handle_message bytes decoding). Consider updating the top-level docstring so it reflects both the message-handling and discovery regression coverage.
| options=[ | ||
| "Charge from Grid", | ||
| "Avoid Discharge", | ||
| "Limit Battery Charge", | ||
| "Discharge Allowed"], | ||
| value_template=val_templ, | ||
| command_template=cmd_templ) |
There was a problem hiding this comment.
send_mqtt_discovery_for_mode passes a list for options, but publish_mqtt_discovery_message currently annotates options as str (and treats it generically). To avoid confusion and improve static analysis, update the options parameter type to a sequence/list of strings (or None) and keep the formatting consistent (e.g., trailing comma / closing bracket on its own line).
batcontrol already supports mode
8(Limit Battery Charge), but the MQTT discovery select only exposed the other three modes.This adds the missing mode to the discovery templates and select options, with a small regression test.