Reduce overhead to call entity services (#106908)

This commit is contained in:
J. Nick Koston
2024-01-07 22:30:52 -10:00
committed by GitHub
parent 9ad3c8dbc9
commit d260ed938a
4 changed files with 59 additions and 36 deletions

View File

@@ -19,7 +19,13 @@ from homeassistant.const import (
STATE_ON,
EntityCategory,
)
from homeassistant.core import Context, HomeAssistant, ServiceCall, SupportsResponse
from homeassistant.core import (
Context,
HassJob,
HomeAssistant,
ServiceCall,
SupportsResponse,
)
from homeassistant.helpers import (
device_registry as dr,
entity_registry as er,
@@ -803,7 +809,7 @@ async def test_call_with_required_features(hass: HomeAssistant, mock_entities) -
await service.entity_service_call(
hass,
mock_entities,
test_service_mock,
HassJob(test_service_mock),
ServiceCall("test_domain", "test_service", {"entity_id": "all"}),
required_features=[SUPPORT_A],
)
@@ -822,7 +828,7 @@ async def test_call_with_required_features(hass: HomeAssistant, mock_entities) -
await service.entity_service_call(
hass,
mock_entities,
test_service_mock,
HassJob(test_service_mock),
ServiceCall(
"test_domain", "test_service", {"entity_id": "light.living_room"}
),
@@ -839,7 +845,7 @@ async def test_call_with_both_required_features(
await service.entity_service_call(
hass,
mock_entities,
test_service_mock,
HassJob(test_service_mock),
ServiceCall("test_domain", "test_service", {"entity_id": "all"}),
required_features=[SUPPORT_A | SUPPORT_B],
)
@@ -858,7 +864,7 @@ async def test_call_with_one_of_required_features(
await service.entity_service_call(
hass,
mock_entities,
test_service_mock,
HassJob(test_service_mock),
ServiceCall("test_domain", "test_service", {"entity_id": "all"}),
required_features=[SUPPORT_A, SUPPORT_C],
)
@@ -879,7 +885,7 @@ async def test_call_with_sync_func(hass: HomeAssistant, mock_entities) -> None:
await service.entity_service_call(
hass,
mock_entities,
test_service_mock,
HassJob(test_service_mock),
ServiceCall("test_domain", "test_service", {"entity_id": "light.kitchen"}),
)
assert test_service_mock.call_count == 1