diff --git a/homeassistant/components/peblar/select.py b/homeassistant/components/peblar/select.py index 37a4f491130c..247fc1ce83fb 100644 --- a/homeassistant/components/peblar/select.py +++ b/homeassistant/components/peblar/select.py @@ -44,11 +44,17 @@ def _smart_charging_options(configuration: PeblarUserConfiguration) -> list[str] A charger without a power meter configured rejects solar charging, and scheduled charging can be switched off during commissioning. Offering those anyway lands the user on a mode the charger quietly ignores. + + Custom solar arrived with firmware 1.10. Rather than check the version, + take the charger at its word: it reports the settings that go with the + mode, and leaves them out when it has never heard of it. """ solar = configuration.solar_charging_allowed + custom = solar and configuration.solar_charging_custom_power_target is not None return [ option for option, allowed in ( + ("custom_solar", custom), ("default", True), ("fast_solar", solar), ("pure_solar", solar), diff --git a/homeassistant/components/peblar/strings.json b/homeassistant/components/peblar/strings.json index afb4fccef947..bd7abf30282b 100644 --- a/homeassistant/components/peblar/strings.json +++ b/homeassistant/components/peblar/strings.json @@ -99,6 +99,7 @@ "smart_charging": { "name": "Smart charging", "state": { + "custom_solar": "Custom solar", "default": "Default", "fast_solar": "Fast solar", "pure_solar": "Pure solar", diff --git a/tests/components/peblar/fixtures/user_configuration.json b/tests/components/peblar/fixtures/user_configuration.json index b41aecd00efa..0d9c4f70e01d 100644 --- a/tests/components/peblar/fixtures/user_configuration.json +++ b/tests/components/peblar/fixtures/user_configuration.json @@ -40,6 +40,9 @@ "SeccOcppUri": "", "SessionManagerChargeWithoutAuth": false, "SolarChargingAllowed": true, + "SolarChargingCustomAlwaysCharge": false, + "SolarChargingCustomPowerTarget": 0, + "SolarChargingCustomPowerThreshold": -1300, "SolarChargingEnable": true, "SolarChargingMode": "PureSolar", "SolarChargingSource": "homewizard", diff --git a/tests/components/peblar/snapshots/test_diagnostics.ambr b/tests/components/peblar/snapshots/test_diagnostics.ambr index 12d671c5100c..00bb3f401f89 100644 --- a/tests/components/peblar/snapshots/test_diagnostics.ambr +++ b/tests/components/peblar/snapshots/test_diagnostics.ambr @@ -138,6 +138,9 @@ 'SeccOcppUri': '', 'SessionManagerChargeWithoutAuth': False, 'SolarChargingAllowed': True, + 'SolarChargingCustomAlwaysCharge': False, + 'SolarChargingCustomPowerTarget': 0, + 'SolarChargingCustomPowerThreshold': -1300, 'SolarChargingEnable': True, 'SolarChargingMode': 'PureSolar', 'SolarChargingSource': 'homewizard', diff --git a/tests/components/peblar/snapshots/test_select.ambr b/tests/components/peblar/snapshots/test_select.ambr index ad6634630f22..bf4b98b5b4b0 100644 --- a/tests/components/peblar/snapshots/test_select.ambr +++ b/tests/components/peblar/snapshots/test_select.ambr @@ -137,6 +137,7 @@ 'area_id': None, 'capabilities': dict({ : list([ + 'custom_solar', 'default', 'fast_solar', 'pure_solar', @@ -179,6 +180,7 @@ 'attributes': ReadOnlyDict({ : 'Peblar EV Charger Smart charging', : list([ + 'custom_solar', 'default', 'fast_solar', 'pure_solar', diff --git a/tests/components/peblar/test_select.py b/tests/components/peblar/test_select.py index 8c3d8b045974..2a974694e2bf 100644 --- a/tests/components/peblar/test_select.py +++ b/tests/components/peblar/test_select.py @@ -262,14 +262,18 @@ async def test_hw_entity_absent_when_hw_flag_false( ), ( {"ScheduledChargingAllowed": False}, - ["default", "fast_solar", "pure_solar", "smart_solar"], + ["custom_solar", "default", "fast_solar", "pure_solar", "smart_solar"], ), ( {"SolarChargingAllowed": False, "ScheduledChargingAllowed": False}, ["default"], ), + ( + {"SolarChargingCustomPowerTarget": None}, + ["default", "fast_solar", "pure_solar", "scheduled", "smart_solar"], + ), ], - ids=["no solar", "no scheduled", "neither"], + ids=["no solar", "no scheduled", "neither", "firmware without custom solar"], indirect=["mock_peblar"], ) @pytest.mark.usefixtures("entity_registry_enabled_by_default") @@ -281,8 +285,30 @@ async def test_smart_charging_options_follow_the_charger( A charger without a power meter rejects solar charging, and the web interface hides those modes. Offering them anyway lets the user pick - something the charger quietly ignores. + something the charger quietly ignores. The same goes for custom solar, + which firmware older than 1.10 has never heard of. """ state = hass.states.get("select.peblar_ev_charger_smart_charging") assert state assert state.attributes[ATTR_OPTIONS] == expected_options + + +@pytest.mark.usefixtures("entity_registry_enabled_by_default") +async def test_selecting_custom_solar( + hass: HomeAssistant, + mock_peblar: MagicMock, +) -> None: + """Test the mode firmware 1.10 added reaches the charger.""" + mock_peblar.smart_charging.reset_mock() + + await hass.services.async_call( + SELECT_DOMAIN, + SERVICE_SELECT_OPTION, + { + ATTR_ENTITY_ID: "select.peblar_ev_charger_smart_charging", + ATTR_OPTION: "custom_solar", + }, + blocking=True, + ) + + mock_peblar.smart_charging.assert_called_once_with(SmartChargingMode.CUSTOM_SOLAR)