mirror of
https://github.com/home-assistant/core.git
synced 2025-08-06 14:15:12 +02:00
Use service_calls fixture in arcam_fmj tests (#119274)
This commit is contained in:
@@ -9,11 +9,7 @@ from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import (
|
||||
MockConfigEntry,
|
||||
async_get_device_automations,
|
||||
async_mock_service,
|
||||
)
|
||||
from tests.common import MockConfigEntry, async_get_device_automations
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
|
||||
@@ -21,12 +17,6 @@ def stub_blueprint_populate_autouse(stub_blueprint_populate: None) -> None:
|
||||
"""Stub copying the blueprints to the config folder."""
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
||||
"""Track calls to a mock service."""
|
||||
return async_mock_service(hass, "test", "automation")
|
||||
|
||||
|
||||
async def test_get_triggers(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
@@ -69,7 +59,7 @@ async def test_get_triggers(
|
||||
async def test_if_fires_on_turn_on_request(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
player_setup,
|
||||
state,
|
||||
) -> None:
|
||||
@@ -111,15 +101,15 @@ async def test_if_fires_on_turn_on_request(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == player_setup
|
||||
assert calls[0].data["id"] == 0
|
||||
assert len(service_calls) == 2
|
||||
assert service_calls[1].data["some"] == player_setup
|
||||
assert service_calls[1].data["id"] == 0
|
||||
|
||||
|
||||
async def test_if_fires_on_turn_on_request_legacy(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
player_setup,
|
||||
state,
|
||||
) -> None:
|
||||
@@ -161,6 +151,6 @@ async def test_if_fires_on_turn_on_request_legacy(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == player_setup
|
||||
assert calls[0].data["id"] == 0
|
||||
assert len(service_calls) == 2
|
||||
assert service_calls[1].data["some"] == player_setup
|
||||
assert service_calls[1].data["id"] == 0
|
||||
|
@@ -51,7 +51,13 @@ from homeassistant.components.websocket_api.http import URL
|
||||
from homeassistant.config import YAML_CONFIG_FILE
|
||||
from homeassistant.config_entries import ConfigEntries, ConfigEntry, ConfigEntryState
|
||||
from homeassistant.const import HASSIO_USER_NAME
|
||||
from homeassistant.core import CoreState, HassJob, HomeAssistant, ServiceCall
|
||||
from homeassistant.core import (
|
||||
CoreState,
|
||||
HassJob,
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
ServiceResponse,
|
||||
)
|
||||
from homeassistant.helpers import (
|
||||
area_registry as ar,
|
||||
category_registry as cr,
|
||||
@@ -1776,18 +1782,30 @@ def label_registry(hass: HomeAssistant) -> lr.LabelRegistry:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def service_calls() -> Generator[None, None, list[ServiceCall]]:
|
||||
def service_calls(hass: HomeAssistant) -> Generator[None, None, list[ServiceCall]]:
|
||||
"""Track all service calls."""
|
||||
calls = []
|
||||
|
||||
_original_async_call = hass.services.async_call
|
||||
|
||||
async def _async_call(
|
||||
self,
|
||||
domain: str,
|
||||
service: str,
|
||||
service_data: dict[str, Any] | None = None,
|
||||
**kwargs: Any,
|
||||
):
|
||||
) -> ServiceResponse:
|
||||
calls.append(ServiceCall(domain, service, service_data))
|
||||
try:
|
||||
return await _original_async_call(
|
||||
domain,
|
||||
service,
|
||||
service_data,
|
||||
**kwargs,
|
||||
)
|
||||
except ha.ServiceNotFound:
|
||||
_LOGGER.debug("Ignoring unknown service call to %s.%s", domain, service)
|
||||
return None
|
||||
|
||||
with patch("homeassistant.core.ServiceRegistry.async_call", _async_call):
|
||||
yield calls
|
||||
|
Reference in New Issue
Block a user