From a46590546750fb00c765ff235f7c4d0b1ad48afd Mon Sep 17 00:00:00 2001 From: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com> Date: Sat, 14 Mar 2026 00:57:16 +0100 Subject: [PATCH] Remove speech parameter from service intent handler (#165225) --- homeassistant/components/cover/intent.py | 2 -- homeassistant/helpers/intent.py | 13 ++----------- tests/components/cover/test_intent.py | 4 ++-- tests/components/intent/test_init.py | 3 +-- tests/helpers/test_intent.py | 15 +++------------ 5 files changed, 8 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/cover/intent.py b/homeassistant/components/cover/intent.py index dfc7d0f69a0..a54cfd98eac 100644 --- a/homeassistant/components/cover/intent.py +++ b/homeassistant/components/cover/intent.py @@ -15,7 +15,6 @@ async def async_setup_intents(hass: HomeAssistant) -> None: INTENT_OPEN_COVER, DOMAIN, SERVICE_OPEN_COVER, - "Opening {}", description="Opens a cover", platforms={DOMAIN}, device_classes={CoverDeviceClass}, @@ -27,7 +26,6 @@ async def async_setup_intents(hass: HomeAssistant) -> None: INTENT_CLOSE_COVER, DOMAIN, SERVICE_CLOSE_COVER, - "Closing {}", description="Closes a cover", platforms={DOMAIN}, device_classes={CoverDeviceClass}, diff --git a/homeassistant/helpers/intent.py b/homeassistant/helpers/intent.py index 97a41552f90..b6d6cd5ad95 100644 --- a/homeassistant/helpers/intent.py +++ b/homeassistant/helpers/intent.py @@ -915,7 +915,7 @@ class DynamicServiceIntentHandler(IntentHandler): def __init__( self, intent_type: str, - speech: str | None = None, + *, required_slots: _IntentSlotsType | None = None, optional_slots: _IntentSlotsType | None = None, required_domains: set[str] | None = None, @@ -927,7 +927,6 @@ class DynamicServiceIntentHandler(IntentHandler): ) -> None: """Create Service Intent Handler.""" self.intent_type = intent_type - self.speech = speech self.required_domains = required_domains self.required_features = required_features self.required_states = required_states @@ -1114,7 +1113,6 @@ class DynamicServiceIntentHandler(IntentHandler): ) for floor in match_result.floors ) - speech_name = match_result.floors[0].name elif match_result.areas: success_results.extend( IntentResponseTarget( @@ -1122,9 +1120,6 @@ class DynamicServiceIntentHandler(IntentHandler): ) for area in match_result.areas ) - speech_name = match_result.areas[0].name - else: - speech_name = states[0].name service_coros: list[Coroutine[Any, Any, None]] = [] for state in states: @@ -1166,9 +1161,6 @@ class DynamicServiceIntentHandler(IntentHandler): states = [hass.states.get(state.entity_id) or state for state in states] response.async_set_states(states) - if self.speech is not None: - response.async_set_speech(self.speech.format(speech_name)) - return response async def async_call_service( @@ -1231,7 +1223,7 @@ class ServiceIntentHandler(DynamicServiceIntentHandler): intent_type: str, domain: str, service: str, - speech: str | None = None, + *, required_slots: _IntentSlotsType | None = None, optional_slots: _IntentSlotsType | None = None, required_domains: set[str] | None = None, @@ -1244,7 +1236,6 @@ class ServiceIntentHandler(DynamicServiceIntentHandler): """Create service handler.""" super().__init__( intent_type, - speech=speech, required_slots=required_slots, optional_slots=optional_slots, required_domains=required_domains, diff --git a/tests/components/cover/test_intent.py b/tests/components/cover/test_intent.py index 383a55e2a72..c4897a01be2 100644 --- a/tests/components/cover/test_intent.py +++ b/tests/components/cover/test_intent.py @@ -43,7 +43,7 @@ async def test_open_cover_intent(hass: HomeAssistant, slots: dict[str, Any]) -> ) await hass.async_block_till_done() - assert response.speech["plain"]["speech"] == "Opening garage door" + assert response.response_type == intent.IntentResponseType.ACTION_DONE assert len(calls) == 1 call = calls[0] assert call.domain == DOMAIN @@ -75,7 +75,7 @@ async def test_close_cover_intent(hass: HomeAssistant, slots: dict[str, Any]) -> ) await hass.async_block_till_done() - assert response.speech["plain"]["speech"] == "Closing garage door" + assert response.response_type == intent.IntentResponseType.ACTION_DONE assert len(calls) == 1 call = calls[0] assert call.domain == DOMAIN diff --git a/tests/components/intent/test_init.py b/tests/components/intent/test_init.py index 20c3a66943b..a0667baae1f 100644 --- a/tests/components/intent/test_init.py +++ b/tests/components/intent/test_init.py @@ -248,12 +248,11 @@ async def test_cover_intents_loading(hass: HomeAssistant) -> None: hass.states.async_set("cover.garage_door", "closed") calls = async_mock_service(hass, "cover", SERVICE_OPEN_COVER) - response = await intent.async_handle( + await intent.async_handle( hass, "test", "HassOpenCover", {"name": {"value": "garage door"}} ) await hass.async_block_till_done() - assert response.speech["plain"]["speech"] == "Opening garage door" assert len(calls) == 1 call = calls[0] assert call.domain == "cover" diff --git a/tests/helpers/test_intent.py b/tests/helpers/test_intent.py index aebd989c237..474e06f5f1b 100644 --- a/tests/helpers/test_intent.py +++ b/tests/helpers/test_intent.py @@ -691,9 +691,7 @@ async def test_validate_then_run_in_background(hass: HomeAssistant) -> None: hass.services.async_register("light", "turn_on", mock_service) # Create intent handler with a service timeout of 0.05 seconds - handler = intent.ServiceIntentHandler( - "TestType", "light", "turn_on", "Turned {} on" - ) + handler = intent.ServiceIntentHandler("TestType", "light", "turn_on") handler.service_timeout = 0.05 intent.async_register(hass, handler) @@ -715,9 +713,7 @@ async def test_validate_then_run_in_background(hass: HomeAssistant) -> None: async def test_invalid_area_floor_names(hass: HomeAssistant) -> None: """Test that we throw an appropriate errors with invalid area/floor names.""" - handler = intent.ServiceIntentHandler( - "TestType", "light", "turn_on", "Turned {} on" - ) + handler = intent.ServiceIntentHandler("TestType", "light", "turn_on") intent.async_register(hass, handler) # Need a light to avoid domain error @@ -752,7 +748,6 @@ async def test_service_intent_handler_required_domains(hass: HomeAssistant) -> N "TestType", "homeassistant", "turn_on", - "Turned {} on", required_domains={"light"}, ) intent.async_register(hass, handler) @@ -792,7 +787,6 @@ async def test_service_handler_empty_strings(hass: HomeAssistant) -> None: "TestType", "light", "turn_on", - "Turned {} on", ) intent.async_register(hass, handler) @@ -818,9 +812,7 @@ async def test_service_handler_empty_strings(hass: HomeAssistant) -> None: async def test_service_handler_no_filter(hass: HomeAssistant) -> None: """Test that targeting all devices in the house fails.""" - handler = intent.ServiceIntentHandler( - "TestType", "light", "turn_on", "Turned {} on" - ) + handler = intent.ServiceIntentHandler("TestType", "light", "turn_on") intent.async_register(hass, handler) with pytest.raises(intent.IntentHandleError): @@ -852,7 +844,6 @@ async def test_service_handler_device_classes( "TestType", "switch", "turn_on", - "Turned {} on", device_classes={switch.SwitchDeviceClass}, ) intent.async_register(hass, handler)