mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Use service_calls fixture in shelly tests (#120991)
This commit is contained in:
parent
07d80d5ad9
commit
3df3e6d081
@ -11,11 +11,11 @@ from homeassistant.components.shelly.const import (
|
||||
EVENT_SHELLY_CLICK,
|
||||
REST_SENSORS_UPDATE_INTERVAL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, ServiceCall
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import MOCK_MAC
|
||||
|
||||
from tests.common import async_capture_events, async_mock_service
|
||||
from tests.common import async_capture_events
|
||||
|
||||
MOCK_SETTINGS = {
|
||||
"name": "Test name",
|
||||
@ -290,12 +290,6 @@ def mock_ws_server():
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def calls(hass: HomeAssistant) -> list[ServiceCall]:
|
||||
"""Track calls to a mock service."""
|
||||
return async_mock_service(hass, "test", "automation")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def events(hass: HomeAssistant):
|
||||
"""Yield caught shelly_click events."""
|
||||
|
@ -178,7 +178,7 @@ async def test_get_triggers_for_invalid_device_id(
|
||||
async def test_if_fires_on_click_event_block_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
mock_block_device: Mock,
|
||||
) -> None:
|
||||
"""Test for click_event trigger firing for block device."""
|
||||
@ -215,14 +215,14 @@ async def test_if_fires_on_click_event_block_device(
|
||||
hass.bus.async_fire(EVENT_SHELLY_CLICK, message)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "test_trigger_single_click"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "test_trigger_single_click"
|
||||
|
||||
|
||||
async def test_if_fires_on_click_event_rpc_device(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
mock_rpc_device: Mock,
|
||||
) -> None:
|
||||
"""Test for click_event trigger firing for rpc device."""
|
||||
@ -259,14 +259,14 @@ async def test_if_fires_on_click_event_rpc_device(
|
||||
hass.bus.async_fire(EVENT_SHELLY_CLICK, message)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "test_trigger_single_push"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "test_trigger_single_push"
|
||||
|
||||
|
||||
async def test_validate_trigger_block_device_not_ready(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
@ -304,14 +304,14 @@ async def test_validate_trigger_block_device_not_ready(
|
||||
hass.bus.async_fire(EVENT_SHELLY_CLICK, message)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "test_trigger_single_click"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "test_trigger_single_click"
|
||||
|
||||
|
||||
async def test_validate_trigger_rpc_device_not_ready(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
@ -349,8 +349,8 @@ async def test_validate_trigger_rpc_device_not_ready(
|
||||
hass.bus.async_fire(EVENT_SHELLY_CLICK, message)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "test_trigger_single_push"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "test_trigger_single_push"
|
||||
|
||||
|
||||
async def test_validate_trigger_invalid_triggers(
|
||||
@ -391,7 +391,7 @@ async def test_validate_trigger_invalid_triggers(
|
||||
async def test_rpc_no_runtime_data(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
mock_rpc_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
@ -429,14 +429,14 @@ async def test_rpc_no_runtime_data(
|
||||
hass.bus.async_fire(EVENT_SHELLY_CLICK, message)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "test_trigger_single_push"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "test_trigger_single_push"
|
||||
|
||||
|
||||
async def test_block_no_runtime_data(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
@ -474,5 +474,5 @@ async def test_block_no_runtime_data(
|
||||
hass.bus.async_fire(EVENT_SHELLY_CLICK, message)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "test_trigger_single"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "test_trigger_single"
|
||||
|
Loading…
x
Reference in New Issue
Block a user