File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -731,13 +731,15 @@ def send_mqtt_discovery_for_mode(self) -> None:
731731 val_templ = (
732732 "{% if value == '-1' %}Charge from Grid"
733733 "{% elif value == '0' %}Avoid Discharge"
734+ "{% elif value == '8' %}Limit Battery Charge"
734735 "{% elif value == '10' %}Discharge Allowed"
735736 "{% else %}Unknown"
736737 "{% endif %}"
737738 )
738739 cmd_templ = (
739740 "{% if value == 'Charge from Grid' %}-1"
740741 "{% elif value == 'Avoid Discharge' %}0"
742+ "{% elif value == 'Limit Battery Charge' %}8"
741743 "{% elif value == 'Discharge Allowed' %}10"
742744 "{% else %}-1"
743745 "{% endif %}"
@@ -754,6 +756,7 @@ def send_mqtt_discovery_for_mode(self) -> None:
754756 options = [
755757 "Charge from Grid" ,
756758 "Avoid Discharge" ,
759+ "Limit Battery Charge" ,
757760 "Discharge Allowed" ],
758761 value_template = val_templ ,
759762 command_template = cmd_templ )
Original file line number Diff line number Diff line change @@ -89,6 +89,33 @@ def test_str_convert_with_plain_string(self):
8989 assert received == ['true' ]
9090
9191
92+ class TestModeDiscovery :
93+ """Mode discovery should expose the full externally supported mode model."""
94+
95+ def test_mode_discovery_includes_limit_battery_charge_mode (self ):
96+ api = MagicMock (spec = MqttApi )
97+ api .base_topic = 'batcontrol'
98+ api .publish_mqtt_discovery_message = MagicMock ()
99+ api .send_mqtt_discovery_for_mode = (
100+ MqttApi .send_mqtt_discovery_for_mode .__get__ (api , MqttApi )
101+ )
102+
103+ api .send_mqtt_discovery_for_mode ()
104+
105+ options = api .publish_mqtt_discovery_message .call_args .kwargs ['options' ]
106+ value_template = api .publish_mqtt_discovery_message .call_args .kwargs ['value_template' ]
107+ command_template = api .publish_mqtt_discovery_message .call_args .kwargs ['command_template' ]
108+
109+ assert options == [
110+ 'Charge from Grid' ,
111+ 'Avoid Discharge' ,
112+ 'Limit Battery Charge' ,
113+ 'Discharge Allowed' ,
114+ ]
115+ assert "{% elif value == '8' %}Limit Battery Charge" in value_template
116+ assert "{% elif value == 'Limit Battery Charge' %}8" in command_template
117+
118+
92119class TestPeakShavingEnabledApi :
93120 """Regression test: peak_shaving/enabled must correctly parse the bytes payload."""
94121
You can’t perform that action at this time.
0 commit comments