diff --git a/homeassistant/components/humidifier/intent.py b/homeassistant/components/humidifier/intent.py index d949874cc67..103521aeb04 100644 --- a/homeassistant/components/humidifier/intent.py +++ b/homeassistant/components/humidifier/intent.py @@ -110,7 +110,7 @@ class SetModeHandler(intent.IntentHandler): intent.async_test_feature(state, HumidifierEntityFeature.MODES, "modes") mode = slots["mode"]["value"] - if mode not in state.attributes.get(ATTR_AVAILABLE_MODES, []): + if mode not in (state.attributes.get(ATTR_AVAILABLE_MODES) or []): raise intent.IntentHandleError( f"Entity {state.name} does not support {mode} mode" ) diff --git a/tests/components/humidifier/test_intent.py b/tests/components/humidifier/test_intent.py index cbdd5c3da26..d8c9f199f57 100644 --- a/tests/components/humidifier/test_intent.py +++ b/tests/components/humidifier/test_intent.py @@ -188,7 +188,10 @@ async def test_intent_set_mode_tests_feature(hass: HomeAssistant) -> None: assert len(mode_calls) == 0 -async def test_intent_set_unknown_mode(hass: HomeAssistant) -> None: +@pytest.mark.parametrize("available_modes", (["home", "away"], None)) +async def test_intent_set_unknown_mode( + hass: HomeAssistant, available_modes: list[str] | None +) -> None: """Test the set mode intent for unsupported mode.""" hass.states.async_set( "humidifier.bedroom_humidifier", @@ -196,8 +199,8 @@ async def test_intent_set_unknown_mode(hass: HomeAssistant) -> None: { ATTR_HUMIDITY: 40, ATTR_SUPPORTED_FEATURES: 1, - ATTR_AVAILABLE_MODES: ["home", "away"], - ATTR_MODE: "home", + ATTR_AVAILABLE_MODES: available_modes, + ATTR_MODE: None, }, ) mode_calls = async_mock_service(hass, DOMAIN, SERVICE_SET_MODE)