Use service_calls fixture in zha tests (#120996)
parent
43806553fc
commit
b0837dd98f
|
@ -20,11 +20,7 @@ from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import device_registry as dr
|
from homeassistant.helpers import device_registry as dr
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.common import (
|
from tests.common import MockConfigEntry, async_get_device_automations
|
||||||
MockConfigEntry,
|
|
||||||
async_get_device_automations,
|
|
||||||
async_mock_service,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
|
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
|
||||||
|
@ -60,12 +56,6 @@ def _same_lists(list_a, list_b):
|
||||||
return all(item in list_b for item in list_a)
|
return all(item in list_b for item in list_a)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
|
||||||
"""Track calls to a mock service."""
|
|
||||||
return async_mock_service(hass, "test", "automation")
|
|
||||||
|
|
||||||
|
|
||||||
async def test_triggers(
|
async def test_triggers(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
|
@ -194,7 +184,7 @@ async def test_no_triggers(
|
||||||
async def test_if_fires_on_event(
|
async def test_if_fires_on_event(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
setup_zha,
|
setup_zha,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for remote triggers firing."""
|
"""Test for remote triggers firing."""
|
||||||
|
@ -262,14 +252,14 @@ async def test_if_fires_on_event(
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 1
|
||||||
assert calls[0].data["message"] == "service called"
|
assert service_calls[0].data["message"] == "service called"
|
||||||
|
|
||||||
|
|
||||||
async def test_device_offline_fires(
|
async def test_device_offline_fires(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
calls: list[ServiceCall],
|
service_calls: list[ServiceCall],
|
||||||
setup_zha,
|
setup_zha,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for device offline triggers firing."""
|
"""Test for device offline triggers firing."""
|
||||||
|
@ -317,14 +307,13 @@ async def test_device_offline_fires(
|
||||||
zha_device.available = False
|
zha_device.available = False
|
||||||
zha_device.emit_zha_event({"device_event_type": "device_offline"})
|
zha_device.emit_zha_event({"device_event_type": "device_offline"})
|
||||||
|
|
||||||
assert len(calls) == 1
|
assert len(service_calls) == 1
|
||||||
assert calls[0].data["message"] == "service called"
|
assert service_calls[0].data["message"] == "service called"
|
||||||
|
|
||||||
|
|
||||||
async def test_exception_no_triggers(
|
async def test_exception_no_triggers(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
calls: list[ServiceCall],
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
setup_zha,
|
setup_zha,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -378,7 +367,6 @@ async def test_exception_no_triggers(
|
||||||
async def test_exception_bad_trigger(
|
async def test_exception_bad_trigger(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
calls: list[ServiceCall],
|
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
setup_zha,
|
setup_zha,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Reference in New Issue