mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use service_calls fixture in nest tests (#120987)
This commit is contained in:
parent
5b39989869
commit
195f07a18a
@ -20,7 +20,7 @@ from homeassistant.util.dt import utcnow
|
||||
|
||||
from .common import DEVICE_ID, CreateDevice, FakeSubscriber, PlatformSetup
|
||||
|
||||
from tests.common import async_get_device_automations, async_mock_service
|
||||
from tests.common import async_get_device_automations
|
||||
|
||||
DEVICE_NAME = "My Camera"
|
||||
DATA_MESSAGE = {"message": "service-called"}
|
||||
@ -83,12 +83,6 @@ async def setup_automation(hass, device_id, trigger_type):
|
||||
)
|
||||
|
||||
|
||||
@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,
|
||||
@ -248,7 +242,7 @@ async def test_fires_on_camera_motion(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test camera_motion triggers firing."""
|
||||
create_device.create(
|
||||
@ -273,8 +267,8 @@ async def test_fires_on_camera_motion(
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == DATA_MESSAGE
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_fires_on_camera_person(
|
||||
@ -282,7 +276,7 @@ async def test_fires_on_camera_person(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test camera_person triggers firing."""
|
||||
create_device.create(
|
||||
@ -307,8 +301,8 @@ async def test_fires_on_camera_person(
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == DATA_MESSAGE
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_fires_on_camera_sound(
|
||||
@ -316,7 +310,7 @@ async def test_fires_on_camera_sound(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test camera_sound triggers firing."""
|
||||
create_device.create(
|
||||
@ -341,8 +335,8 @@ async def test_fires_on_camera_sound(
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == DATA_MESSAGE
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_fires_on_doorbell_chime(
|
||||
@ -350,7 +344,7 @@ async def test_fires_on_doorbell_chime(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test doorbell_chime triggers firing."""
|
||||
create_device.create(
|
||||
@ -375,8 +369,8 @@ async def test_fires_on_doorbell_chime(
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == DATA_MESSAGE
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data == DATA_MESSAGE
|
||||
|
||||
|
||||
async def test_trigger_for_wrong_device_id(
|
||||
@ -384,7 +378,7 @@ async def test_trigger_for_wrong_device_id(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test messages for the wrong device are ignored."""
|
||||
create_device.create(
|
||||
@ -409,7 +403,7 @@ async def test_trigger_for_wrong_device_id(
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
assert len(service_calls) == 0
|
||||
|
||||
|
||||
async def test_trigger_for_wrong_event_type(
|
||||
@ -417,7 +411,7 @@ async def test_trigger_for_wrong_event_type(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test that messages for the wrong event type are ignored."""
|
||||
create_device.create(
|
||||
@ -442,13 +436,13 @@ async def test_trigger_for_wrong_event_type(
|
||||
}
|
||||
hass.bus.async_fire(NEST_EVENT, message)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 0
|
||||
assert len(service_calls) == 0
|
||||
|
||||
|
||||
async def test_subscriber_automation(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
create_device: CreateDevice,
|
||||
setup_platform: PlatformSetup,
|
||||
subscriber: FakeSubscriber,
|
||||
@ -488,5 +482,5 @@ async def test_subscriber_automation(
|
||||
await subscriber.async_receive_event(event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data == DATA_MESSAGE
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data == DATA_MESSAGE
|
||||
|
Loading…
x
Reference in New Issue
Block a user