mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Support multiple responses for service calls (#96370)
* add supports_response to platform entity services * support multiple entities in entity_service_call * support legacy response format for service calls * revert changes to script/shell_command * add back test for multiple responses for legacy service * remove SupportsResponse.ONLY_LEGACY * Apply suggestion Co-authored-by: Allen Porter <allen.porter@gmail.com> * test for entity_id remove None * revert Apply suggestion * return EntityServiceResponse from _handle_entity_call * Use asyncio.gather * EntityServiceResponse not Optional * styling --------- Co-authored-by: Allen Porter <allen.porter@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b86f3be510
commit
06c9719cd6
@@ -20,8 +20,10 @@ from homeassistant.core import (
|
||||
CALLBACK_TYPE,
|
||||
DOMAIN as HOMEASSISTANT_DOMAIN,
|
||||
CoreState,
|
||||
EntityServiceResponse,
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
SupportsResponse,
|
||||
callback,
|
||||
split_entity_id,
|
||||
valid_entity_id,
|
||||
@@ -814,6 +816,7 @@ class EntityPlatform:
|
||||
schema: dict[str, Any] | vol.Schema,
|
||||
func: str | Callable[..., Any],
|
||||
required_features: Iterable[int] | None = None,
|
||||
supports_response: SupportsResponse = SupportsResponse.NONE,
|
||||
) -> None:
|
||||
"""Register an entity service.
|
||||
|
||||
@@ -825,9 +828,9 @@ class EntityPlatform:
|
||||
if isinstance(schema, dict):
|
||||
schema = cv.make_entity_service_schema(schema)
|
||||
|
||||
async def handle_service(call: ServiceCall) -> None:
|
||||
async def handle_service(call: ServiceCall) -> EntityServiceResponse | None:
|
||||
"""Handle the service."""
|
||||
await service.entity_service_call(
|
||||
return await service.entity_service_call(
|
||||
self.hass,
|
||||
[
|
||||
plf
|
||||
@@ -840,7 +843,7 @@ class EntityPlatform:
|
||||
)
|
||||
|
||||
self.hass.services.async_register(
|
||||
self.platform_name, name, handle_service, schema
|
||||
self.platform_name, name, handle_service, schema, supports_response
|
||||
)
|
||||
|
||||
async def _update_entity_states(self, now: datetime) -> None:
|
||||
|
||||
Reference in New Issue
Block a user