mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Use service_calls fixture in xiaomi_ble tests (#120998)
This commit is contained in:
parent
3adea1ada9
commit
326d24d78b
@ -18,7 +18,6 @@ from tests.common import (
|
|||||||
MockConfigEntry,
|
MockConfigEntry,
|
||||||
async_capture_events,
|
async_capture_events,
|
||||||
async_get_device_automations,
|
async_get_device_automations,
|
||||||
async_mock_service,
|
|
||||||
)
|
)
|
||||||
from tests.components.bluetooth import inject_bluetooth_service_info_bleak
|
from tests.components.bluetooth import inject_bluetooth_service_info_bleak
|
||||||
|
|
||||||
@ -29,12 +28,6 @@ def get_device_id(mac: str) -> tuple[str, str]:
|
|||||||
return (BLUETOOTH_DOMAIN, mac)
|
return (BLUETOOTH_DOMAIN, mac)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
|
||||||
"""Track calls to a mock service."""
|
|
||||||
return async_mock_service(hass, "test", "automation")
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup_xiaomi_device(
|
async def _async_setup_xiaomi_device(
|
||||||
hass: HomeAssistant, mac: str, data: Any | None = None
|
hass: HomeAssistant, mac: str, data: Any | None = None
|
||||||
):
|
):
|
||||||
@ -399,7 +392,9 @@ async def test_get_triggers_for_invalid_device_id(
|
|||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_button_press(
|
async def test_if_fires_on_button_press(
|
||||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall]
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for button press event trigger firing."""
|
"""Test for button press event trigger firing."""
|
||||||
mac = "54:EF:44:E3:9C:BC"
|
mac = "54:EF:44:E3:9C:BC"
|
||||||
@ -452,15 +447,17 @@ async def test_if_fires_on_button_press(
|
|||||||
)
|
)
|
||||||
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["some"] == "test_trigger_button_press"
|
assert service_calls[0].data["some"] == "test_trigger_button_press"
|
||||||
|
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_double_button_long_press(
|
async def test_if_fires_on_double_button_long_press(
|
||||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall]
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for button press event trigger firing."""
|
"""Test for button press event trigger firing."""
|
||||||
mac = "DC:ED:83:87:12:73"
|
mac = "DC:ED:83:87:12:73"
|
||||||
@ -513,15 +510,17 @@ async def test_if_fires_on_double_button_long_press(
|
|||||||
)
|
)
|
||||||
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["some"] == "test_trigger_right_button_press"
|
assert service_calls[0].data["some"] == "test_trigger_right_button_press"
|
||||||
|
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
async def test_if_fires_on_motion_detected(
|
async def test_if_fires_on_motion_detected(
|
||||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall]
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for motion event trigger firing."""
|
"""Test for motion event trigger firing."""
|
||||||
mac = "DE:70:E8:B2:39:0C"
|
mac = "DE:70:E8:B2:39:0C"
|
||||||
@ -567,8 +566,8 @@ async def test_if_fires_on_motion_detected(
|
|||||||
)
|
)
|
||||||
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["some"] == "test_trigger_motion_detected"
|
assert service_calls[0].data["some"] == "test_trigger_motion_detected"
|
||||||
|
|
||||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -676,7 +675,9 @@ async def test_automation_with_invalid_trigger_event_property(
|
|||||||
|
|
||||||
|
|
||||||
async def test_triggers_for_invalid__model(
|
async def test_triggers_for_invalid__model(
|
||||||
hass: HomeAssistant, device_registry: dr.DeviceRegistry, calls: list[ServiceCall]
|
hass: HomeAssistant,
|
||||||
|
device_registry: dr.DeviceRegistry,
|
||||||
|
service_calls: list[ServiceCall],
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test invalid model doesn't return triggers."""
|
"""Test invalid model doesn't return triggers."""
|
||||||
mac = "DE:70:E8:B2:39:0C"
|
mac = "DE:70:E8:B2:39:0C"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user