Remove EntityComponent.async_register_legacy_entity_service (#152539)

This commit is contained in:
Erik Montnemery
2025-09-18 20:34:25 +02:00
committed by GitHub
parent 6d3ad3ab9c
commit 5bd39804f1
2 changed files with 1 additions and 81 deletions

View File

@@ -18,11 +18,9 @@ from homeassistant.const import (
) )
from homeassistant.core import ( from homeassistant.core import (
Event, Event,
HassJob,
HassJobType, HassJobType,
HomeAssistant, HomeAssistant,
ServiceCall, ServiceCall,
ServiceResponse,
SupportsResponse, SupportsResponse,
callback, callback,
) )
@@ -31,14 +29,7 @@ from homeassistant.loader import async_get_integration, bind_hass
from homeassistant.setup import async_prepare_setup_platform from homeassistant.setup import async_prepare_setup_platform
from homeassistant.util.hass_dict import HassKey from homeassistant.util.hass_dict import HassKey
from . import ( from . import device_registry as dr, discovery, entity, entity_registry as er, service
config_validation as cv,
device_registry as dr,
discovery,
entity,
entity_registry as er,
service,
)
from .entity_platform import EntityPlatform, async_calculate_suggested_object_id from .entity_platform import EntityPlatform, async_calculate_suggested_object_id
from .typing import ConfigType, DiscoveryInfoType, VolDictType, VolSchemaType from .typing import ConfigType, DiscoveryInfoType, VolDictType, VolSchemaType
@@ -252,43 +243,6 @@ class EntityComponent[_EntityT: entity.Entity = entity.Entity]:
self.hass, self.entities, service_call, expand_group self.hass, self.entities, service_call, expand_group
) )
@callback
def async_register_legacy_entity_service(
self,
name: str,
schema: VolDictType | VolSchemaType,
func: str | Callable[..., Any],
required_features: list[int] | None = None,
supports_response: SupportsResponse = SupportsResponse.NONE,
) -> None:
"""Register an entity service with a legacy response format."""
if isinstance(schema, dict):
schema = cv.make_entity_service_schema(schema)
service_func: str | HassJob[..., Any]
service_func = func if isinstance(func, str) else HassJob(func)
async def handle_service(
call: ServiceCall,
) -> ServiceResponse:
"""Handle the service."""
result = await service.entity_service_call(
self.hass, self._entities, service_func, call, required_features
)
if result:
if len(result) > 1:
raise HomeAssistantError(
"Deprecated service call matched more than one entity"
)
return result.popitem()[1]
return None
self.hass.services.async_register(
self.domain, name, handle_service, schema, supports_response
)
@callback @callback
def async_register_entity_service( def async_register_entity_service(
self, self,

View File

@@ -694,40 +694,6 @@ async def test_register_entity_service_response_data_multiple_matches_raises(
) )
async def test_legacy_register_entity_service_response_data_multiple_matches(
hass: HomeAssistant,
) -> None:
"""Test asking for legacy service response data but matching many entities."""
entity1 = MockEntity(entity_id=f"{DOMAIN}.entity1")
entity2 = MockEntity(entity_id=f"{DOMAIN}.entity2")
async def generate_response(
target: MockEntity, call: ServiceCall
) -> ServiceResponse:
return {"response-key": "response-value"}
component = EntityComponent(_LOGGER, DOMAIN, hass)
await component.async_setup({})
await component.async_add_entities([entity1, entity2])
component.async_register_legacy_entity_service(
"hello",
{"some": str},
generate_response,
supports_response=SupportsResponse.ONLY,
)
with pytest.raises(HomeAssistantError, match="matched more than one entity"):
await hass.services.async_call(
DOMAIN,
"hello",
service_data={"some": "data"},
target={"entity_id": [entity1.entity_id, entity2.entity_id]},
blocking=True,
return_response=True,
)
async def test_platforms_shutdown_on_stop(hass: HomeAssistant) -> None: async def test_platforms_shutdown_on_stop(hass: HomeAssistant) -> None:
"""Test that we shutdown platforms on stop.""" """Test that we shutdown platforms on stop."""
platform1_setup = Mock(side_effect=[PlatformNotReady, PlatformNotReady, None]) platform1_setup = Mock(side_effect=[PlatformNotReady, PlatformNotReady, None])