1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-02 00:20:30 +01:00

Remove speech parameter from service intent handler (#165225)

This commit is contained in:
Artur Pragacz
2026-03-14 00:57:16 +01:00
committed by GitHub
parent a47faa3ced
commit a465905467
5 changed files with 8 additions and 29 deletions

View File

@@ -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},

View File

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

View File

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

View File

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

View File

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