From 0ba123bebba9df63cd42520aeb45cd7280c475a9 Mon Sep 17 00:00:00 2001 From: Armand Cadet Date: Wed, 2 Dec 2026 13:13:15 +0100 Subject: [PATCH] Refuse Whirlpool oven cook mode changes while cooking (#195882) Co-authored-by: armandkd <4838021+armandkd@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- homeassistant/components/whirlpool/select.py | 8 ++++++ .../components/whirlpool/strings.json | 3 ++ tests/components/whirlpool/test_select.py | 28 +++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/homeassistant/components/whirlpool/select.py b/homeassistant/components/whirlpool/select.py index f98640da35d0..2801ad1b9b00 100644 --- a/homeassistant/components/whirlpool/select.py +++ b/homeassistant/components/whirlpool/select.py @@ -139,6 +139,14 @@ class WhirlpoolOvenCookModeSelect(WhirlpoolOvenEntity, SelectEntity): # the current cook, not by starting a "standby" cook. result = await self._appliance.stop_cook(self.cavity) else: + current = self._appliance.get_cook_mode(self.cavity) + if current not in (None, CookMode.Standby, mode): + # Like the Whirlpool app, the oven doesn't change the mode + # of a running cook: it ignores the command. + raise ServiceValidationError( + translation_domain=DOMAIN, + translation_key="cook_mode_change_while_cooking", + ) target = self._appliance.get_target_temp(self.cavity) if target is None: target = DEFAULT_OVEN_TEMP diff --git a/homeassistant/components/whirlpool/strings.json b/homeassistant/components/whirlpool/strings.json index 4ae317a1e3b5..62a16326ad67 100644 --- a/homeassistant/components/whirlpool/strings.json +++ b/homeassistant/components/whirlpool/strings.json @@ -290,6 +290,9 @@ "cannot_connect": { "message": "[%key:common::config_flow::error::cannot_connect%]" }, + "cook_mode_change_while_cooking": { + "message": "The cook mode cannot be changed while the oven is cooking. Stop the current cook first." + }, "invalid_auth": { "message": "[%key:common::config_flow::error::invalid_auth%]" }, diff --git a/tests/components/whirlpool/test_select.py b/tests/components/whirlpool/test_select.py index 6f57ffc3a42f..de12ed3fcdfc 100644 --- a/tests/components/whirlpool/test_select.py +++ b/tests/components/whirlpool/test_select.py @@ -154,6 +154,7 @@ async def test_oven_cook_mode_select( """Test selecting a cook mode issues a cook command.""" entity_id, mock_fixture, cavity = oven_cook_mode_entity mock = request.getfixturevalue(mock_fixture) + mock.get_cook_mode.return_value = whirlpool.oven.CookMode.Standby await init_integration(hass) await hass.services.async_call( @@ -170,6 +171,31 @@ async def test_oven_cook_mode_select( ) +async def test_oven_cook_mode_select_while_cooking( + hass: HomeAssistant, + oven_cook_mode_entity: tuple[str, str, whirlpool.oven.Cavity], + request: pytest.FixtureRequest, +) -> None: + """Test changing the mode of a running cook is refused.""" + entity_id, mock_fixture, _ = oven_cook_mode_entity + mock = request.getfixturevalue(mock_fixture) + await init_integration(hass) + + with pytest.raises(ServiceValidationError) as err: + await hass.services.async_call( + SELECT_DOMAIN, + SelectService.SELECT_OPTION, + { + TargetKey.ENTITY_ID: entity_id, + SelectServiceArgument.OPTION: "broil", + }, + blocking=True, + ) + assert err.value.translation_key == "cook_mode_change_while_cooking" + mock.set_cook.assert_not_called() + mock.stop_cook.assert_not_called() + + async def test_oven_cook_mode_select_from_idle( hass: HomeAssistant, oven_cook_mode_entity: tuple[str, str, whirlpool.oven.Cavity], @@ -178,6 +204,7 @@ async def test_oven_cook_mode_select_from_idle( """Test selecting a mode with no target set uses the default temperature.""" entity_id, mock_fixture, cavity = oven_cook_mode_entity mock = request.getfixturevalue(mock_fixture) + mock.get_cook_mode.return_value = whirlpool.oven.CookMode.Standby mock.get_target_temp.return_value = None await init_integration(hass) @@ -226,6 +253,7 @@ async def test_oven_cook_mode_select_value_error( """Test a ValueError while setting the cook mode raises ServiceValidationError.""" entity_id, mock_fixture, _ = oven_cook_mode_entity mock = request.getfixturevalue(mock_fixture) + mock.get_cook_mode.return_value = whirlpool.oven.CookMode.Standby mock.set_cook.side_effect = ValueError await init_integration(hass)