Use service_calls fixture in lutron_caseta tests (#120934)

This commit is contained in:
epenet 2024-07-01 17:24:36 +02:00 committed by GitHub
parent 38aa6bcf19
commit 2815c43f3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,11 +39,7 @@ from homeassistant.setup import async_setup_component
from . import MockBridge from . import MockBridge
from tests.common import ( from tests.common import MockConfigEntry, async_get_device_automations
MockConfigEntry,
async_get_device_automations,
async_mock_service,
)
MOCK_BUTTON_DEVICES = [ MOCK_BUTTON_DEVICES = [
{ {
@ -102,12 +98,6 @@ MOCK_BUTTON_DEVICES = [
] ]
@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_lutron_with_picos(hass): async def _async_setup_lutron_with_picos(hass):
"""Setups a lutron bridge with picos.""" """Setups a lutron bridge with picos."""
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
@ -220,7 +210,9 @@ async def test_none_serial_keypad(
async def test_if_fires_on_button_event( async def test_if_fires_on_button_event(
hass: HomeAssistant, calls: list[ServiceCall], device_registry: dr.DeviceRegistry hass: HomeAssistant,
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test for press trigger firing.""" """Test for press trigger firing."""
await _async_setup_lutron_with_picos(hass) await _async_setup_lutron_with_picos(hass)
@ -266,12 +258,14 @@ async def test_if_fires_on_button_event(
hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message) hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message)
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"
async def test_if_fires_on_button_event_without_lip( async def test_if_fires_on_button_event_without_lip(
hass: HomeAssistant, calls: list[ServiceCall], device_registry: dr.DeviceRegistry hass: HomeAssistant,
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test for press trigger firing on a device that does not support lip.""" """Test for press trigger firing on a device that does not support lip."""
await _async_setup_lutron_with_picos(hass) await _async_setup_lutron_with_picos(hass)
@ -315,12 +309,12 @@ async def test_if_fires_on_button_event_without_lip(
hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message) hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message)
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"
async def test_validate_trigger_config_no_device( async def test_validate_trigger_config_no_device(
hass: HomeAssistant, calls: list[ServiceCall] hass: HomeAssistant, service_calls: list[ServiceCall]
) -> None: ) -> None:
"""Test for no press with no device.""" """Test for no press with no device."""
@ -356,11 +350,11 @@ async def test_validate_trigger_config_no_device(
hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message) hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 0 assert len(service_calls) == 0
async def test_validate_trigger_config_unknown_device( async def test_validate_trigger_config_unknown_device(
hass: HomeAssistant, calls: list[ServiceCall] hass: HomeAssistant, service_calls: list[ServiceCall]
) -> None: ) -> None:
"""Test for no press with an unknown device.""" """Test for no press with an unknown device."""
@ -404,7 +398,7 @@ async def test_validate_trigger_config_unknown_device(
hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message) hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message)
await hass.async_block_till_done() await hass.async_block_till_done()
assert len(calls) == 0 assert len(service_calls) == 0
async def test_validate_trigger_invalid_triggers( async def test_validate_trigger_invalid_triggers(
@ -444,7 +438,9 @@ async def test_validate_trigger_invalid_triggers(
async def test_if_fires_on_button_event_late_setup( async def test_if_fires_on_button_event_late_setup(
hass: HomeAssistant, calls: list[ServiceCall], device_registry: dr.DeviceRegistry hass: HomeAssistant,
service_calls: list[ServiceCall],
device_registry: dr.DeviceRegistry,
) -> None: ) -> None:
"""Test for press trigger firing with integration getting setup late.""" """Test for press trigger firing with integration getting setup late."""
config_entry_id = await _async_setup_lutron_with_picos(hass) config_entry_id = await _async_setup_lutron_with_picos(hass)
@ -495,5 +491,5 @@ async def test_if_fires_on_button_event_late_setup(
hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message) hass.bus.async_fire(LUTRON_CASETA_BUTTON_EVENT, message)
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"