Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/batcontrol/mqtt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ def send_mqtt_discovery_messages(self) -> None:
max_value=10000,
initial_value=10000)

self.publish_mqtt_discovery_message(
"Limit Battery Charge Rate",
"batcontrol_limit_battery_charge_rate",
"number",
"power",
"W",
self.base_topic +
"/limit_battery_charge_rate",
self.base_topic +
"/limit_battery_charge_rate/set",
entity_category="config",
min_value=-1,
max_value=10000,
initial_value=-1)

self.publish_mqtt_discovery_message(
"Always Allow Discharge Limit",
"batcontrol_always_allow_discharge_limit",
Expand Down
28 changes: 28 additions & 0 deletions tests/batcontrol/test_mqtt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,34 @@ def test_mode_discovery_includes_limit_battery_charge_mode(self):
class TestDiscoveryMessages:
"""Discovery should expose key externally visible runtime state."""

def test_discovery_includes_limit_battery_charge_rate_number(self):
api = MagicMock(spec=MqttApi)
api.base_topic = 'batcontrol'
api.publish_mqtt_discovery_message = MagicMock()
api.send_mqtt_discovery_for_mode = MagicMock()
api.send_mqtt_discovery_messages = (
MqttApi.send_mqtt_discovery_messages.__get__(api, MqttApi)
)

api.send_mqtt_discovery_messages()

assert any(
call.args[:3] == (
'Limit Battery Charge Rate',
'batcontrol_limit_battery_charge_rate',
'number',
)
and call.args[3] == 'power'
and call.args[4] == 'W'
and call.args[5] == 'batcontrol/limit_battery_charge_rate'
and call.args[6] == 'batcontrol/limit_battery_charge_rate/set'
and call.kwargs['entity_category'] == 'config'
and call.kwargs['min_value'] == -1
and call.kwargs['max_value'] == 10000
and call.kwargs['initial_value'] == -1
for call in api.publish_mqtt_discovery_message.call_args_list
)

def test_discovery_includes_api_override_active_binary_sensor(self):
api = MagicMock(spec=MqttApi)
api.base_topic = 'batcontrol'
Expand Down