Skip to content

Commit 4e67b1c

Browse files
mqtt: expose limit battery charge rate in discovery (#342)
1 parent 8cf9402 commit 4e67b1c

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

src/batcontrol/mqtt_api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,21 @@ def send_mqtt_discovery_messages(self) -> None:
527527
max_value=10000,
528528
initial_value=10000)
529529

530+
self.publish_mqtt_discovery_message(
531+
"Limit Battery Charge Rate",
532+
"batcontrol_limit_battery_charge_rate",
533+
"number",
534+
"power",
535+
"W",
536+
self.base_topic +
537+
"/limit_battery_charge_rate",
538+
self.base_topic +
539+
"/limit_battery_charge_rate/set",
540+
entity_category="config",
541+
min_value=-1,
542+
max_value=10000,
543+
initial_value=-1)
544+
530545
self.publish_mqtt_discovery_message(
531546
"Always Allow Discharge Limit",
532547
"batcontrol_always_allow_discharge_limit",

tests/batcontrol/test_mqtt_api.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,34 @@ def test_mode_discovery_includes_limit_battery_charge_mode(self):
119119
class TestDiscoveryMessages:
120120
"""Discovery should expose key externally visible runtime state."""
121121

122+
def test_discovery_includes_limit_battery_charge_rate_number(self):
123+
api = MagicMock(spec=MqttApi)
124+
api.base_topic = 'batcontrol'
125+
api.publish_mqtt_discovery_message = MagicMock()
126+
api.send_mqtt_discovery_for_mode = MagicMock()
127+
api.send_mqtt_discovery_messages = (
128+
MqttApi.send_mqtt_discovery_messages.__get__(api, MqttApi)
129+
)
130+
131+
api.send_mqtt_discovery_messages()
132+
133+
assert any(
134+
call.args[:3] == (
135+
'Limit Battery Charge Rate',
136+
'batcontrol_limit_battery_charge_rate',
137+
'number',
138+
)
139+
and call.args[3] == 'power'
140+
and call.args[4] == 'W'
141+
and call.args[5] == 'batcontrol/limit_battery_charge_rate'
142+
and call.args[6] == 'batcontrol/limit_battery_charge_rate/set'
143+
and call.kwargs['entity_category'] == 'config'
144+
and call.kwargs['min_value'] == -1
145+
and call.kwargs['max_value'] == 10000
146+
and call.kwargs['initial_value'] == -1
147+
for call in api.publish_mqtt_discovery_message.call_args_list
148+
)
149+
122150
def test_discovery_includes_api_override_active_binary_sensor(self):
123151
api = MagicMock(spec=MqttApi)
124152
api.base_topic = 'batcontrol'

0 commit comments

Comments
 (0)