Fix unhandled exception on humidifier intent when available_modes is None (#108802)

pull/108620/head
Jan Bouwhuis 2024-01-24 22:14:15 +01:00 committed by GitHub
parent de38e7a367
commit 066692506c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 4 deletions

View File

@ -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"
)

View File

@ -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)