Rename service_calls fixture in template tests (#118358)

This commit is contained in:
epenet 2024-05-29 10:27:52 +02:00 committed by GitHub
parent cae22e5109
commit bead6b0094
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -18,20 +18,20 @@ from homeassistant.const import (
STATE_ALARM_PENDING, STATE_ALARM_PENDING,
STATE_ALARM_TRIGGERED, STATE_ALARM_TRIGGERED,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import Event, HomeAssistant, callback
TEMPLATE_NAME = "alarm_control_panel.test_template_panel" TEMPLATE_NAME = "alarm_control_panel.test_template_panel"
PANEL_NAME = "alarm_control_panel.test" PANEL_NAME = "alarm_control_panel.test"
@pytest.fixture @pytest.fixture
def service_calls(hass): def call_service_events(hass: HomeAssistant) -> list[Event]:
"""Track service call events for alarm_control_panel.test.""" """Track service call events for alarm_control_panel.test."""
events = [] events: list[Event] = []
entity_id = "alarm_control_panel.test" entity_id = "alarm_control_panel.test"
@callback @callback
def capture_events(event): def capture_events(event: Event) -> None:
if event.data[ATTR_DOMAIN] != ALARM_DOMAIN: if event.data[ATTR_DOMAIN] != ALARM_DOMAIN:
return return
if event.data[ATTR_SERVICE_DATA][ATTR_ENTITY_ID] != [entity_id]: if event.data[ATTR_SERVICE_DATA][ATTR_ENTITY_ID] != [entity_id]:
@ -281,15 +281,17 @@ async def test_name(hass: HomeAssistant, start_ha) -> None:
"alarm_trigger", "alarm_trigger",
], ],
) )
async def test_actions(hass: HomeAssistant, service, start_ha, service_calls) -> None: async def test_actions(
hass: HomeAssistant, service, start_ha, call_service_events: list[Event]
) -> None:
"""Test alarm actions.""" """Test alarm actions."""
await hass.services.async_call( await hass.services.async_call(
ALARM_DOMAIN, service, {"entity_id": TEMPLATE_NAME}, blocking=True ALARM_DOMAIN, service, {"entity_id": TEMPLATE_NAME}, blocking=True
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(service_calls) == 1 assert len(call_service_events) == 1
assert service_calls[0].data["service"] == service assert call_service_events[0].data["service"] == service
assert service_calls[0].data["service_data"]["code"] == TEMPLATE_NAME assert call_service_events[0].data["service_data"]["code"] == TEMPLATE_NAME
@pytest.mark.parametrize(("count", "domain"), [(1, "alarm_control_panel")]) @pytest.mark.parametrize(("count", "domain"), [(1, "alarm_control_panel")])