1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Allow stopping a script with a response value (#95284)

This commit is contained in:
Paulus Schoutsen
2023-06-27 02:24:22 -04:00
committed by GitHub
parent 51aa2ba835
commit 5f14cdf69d
10 changed files with 140 additions and 28 deletions

View File

@@ -48,7 +48,9 @@ from homeassistant.core import (
Event,
HomeAssistant,
ServiceCall,
ServiceResponse,
State,
SupportsResponse,
callback,
)
from homeassistant.helpers import (
@@ -285,7 +287,12 @@ async def async_test_home_assistant(event_loop, load_registries=True):
def async_mock_service(
hass: HomeAssistant, domain: str, service: str, schema: vol.Schema | None = None
hass: HomeAssistant,
domain: str,
service: str,
schema: vol.Schema | None = None,
response: ServiceResponse = None,
supports_response: SupportsResponse | None = None,
) -> list[ServiceCall]:
"""Set up a fake service & return a calls log list to this service."""
calls = []
@@ -294,8 +301,18 @@ def async_mock_service(
def mock_service_log(call): # pylint: disable=unnecessary-lambda
"""Mock service call."""
calls.append(call)
return response
hass.services.async_register(domain, service, mock_service_log, schema=schema)
if supports_response is None and response is not None:
supports_response = SupportsResponse.OPTIONAL
hass.services.async_register(
domain,
service,
mock_service_log,
schema=schema,
supports_response=supports_response,
)
return calls