mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 04:35:11 +02:00
Use service_calls fixture in homekit_controller tests (#120927)
This commit is contained in:
@@ -15,7 +15,7 @@ from homeassistant.setup import async_setup_component
|
||||
|
||||
from .common import setup_test_component
|
||||
|
||||
from tests.common import async_get_device_automations, async_mock_service
|
||||
from tests.common import async_get_device_automations
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True, name="stub_blueprint_populate")
|
||||
@@ -23,12 +23,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")
|
||||
|
||||
|
||||
def create_remote(accessory):
|
||||
"""Define characteristics for a button (that is inn a group)."""
|
||||
service_label = accessory.add_service(ServicesTypes.SERVICE_LABEL)
|
||||
@@ -239,7 +233,7 @@ async def test_handle_events(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test that events are handled."""
|
||||
helper = await setup_test_component(hass, create_remote)
|
||||
@@ -303,8 +297,8 @@ async def test_handle_events(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "device - button1 - single_press - 0"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "device - button1 - single_press - 0"
|
||||
|
||||
# Make sure automation doesn't trigger for long press
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -312,7 +306,7 @@ async def test_handle_events(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert len(service_calls) == 1
|
||||
|
||||
# Make sure automation doesn't trigger for double press
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -320,7 +314,7 @@ async def test_handle_events(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert len(service_calls) == 1
|
||||
|
||||
# Make sure second automation fires for long press
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -328,8 +322,8 @@ async def test_handle_events(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data["some"] == "device - button2 - long_press - 0"
|
||||
assert len(service_calls) == 2
|
||||
assert service_calls[1].data["some"] == "device - button2 - long_press - 0"
|
||||
|
||||
# Turn the automations off
|
||||
await hass.services.async_call(
|
||||
@@ -338,6 +332,7 @@ async def test_handle_events(
|
||||
{"entity_id": "automation.long_press"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(service_calls) == 3
|
||||
|
||||
await hass.services.async_call(
|
||||
"automation",
|
||||
@@ -345,6 +340,7 @@ async def test_handle_events(
|
||||
{"entity_id": "automation.single_press"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(service_calls) == 4
|
||||
|
||||
# Make sure event no longer fires
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -352,14 +348,14 @@ async def test_handle_events(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert len(service_calls) == 4
|
||||
|
||||
|
||||
async def test_handle_events_late_setup(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
calls: list[ServiceCall],
|
||||
service_calls: list[ServiceCall],
|
||||
) -> None:
|
||||
"""Test that events are handled when setup happens after startup."""
|
||||
helper = await setup_test_component(hass, create_remote)
|
||||
@@ -432,8 +428,8 @@ async def test_handle_events_late_setup(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == "device - button1 - single_press - 0"
|
||||
assert len(service_calls) == 1
|
||||
assert service_calls[0].data["some"] == "device - button1 - single_press - 0"
|
||||
|
||||
# Make sure automation doesn't trigger for a polled None
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -441,7 +437,7 @@ async def test_handle_events_late_setup(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert len(service_calls) == 1
|
||||
|
||||
# Make sure automation doesn't trigger for long press
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -449,7 +445,7 @@ async def test_handle_events_late_setup(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert len(service_calls) == 1
|
||||
|
||||
# Make sure automation doesn't trigger for double press
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -457,7 +453,7 @@ async def test_handle_events_late_setup(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert len(service_calls) == 1
|
||||
|
||||
# Make sure second automation fires for long press
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -465,8 +461,8 @@ async def test_handle_events_late_setup(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[1].data["some"] == "device - button2 - long_press - 0"
|
||||
assert len(service_calls) == 2
|
||||
assert service_calls[1].data["some"] == "device - button2 - long_press - 0"
|
||||
|
||||
# Turn the automations off
|
||||
await hass.services.async_call(
|
||||
@@ -475,6 +471,7 @@ async def test_handle_events_late_setup(
|
||||
{"entity_id": "automation.long_press"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(service_calls) == 3
|
||||
|
||||
await hass.services.async_call(
|
||||
"automation",
|
||||
@@ -482,6 +479,7 @@ async def test_handle_events_late_setup(
|
||||
{"entity_id": "automation.single_press"},
|
||||
blocking=True,
|
||||
)
|
||||
assert len(service_calls) == 4
|
||||
|
||||
# Make sure event no longer fires
|
||||
helper.pairing.testing.update_named_service(
|
||||
@@ -489,4 +487,4 @@ async def test_handle_events_late_setup(
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert len(service_calls) == 4
|
||||
|
Reference in New Issue
Block a user