Use service_calls fixture in bthome tests (#119268)

This commit is contained in:
epenet 2024-06-10 10:05:47 +02:00 committed by GitHub
parent a5cde4b32b
commit 42f3dd636f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,7 +1,5 @@
"""Test BTHome BLE events.""" """Test BTHome BLE events."""
import pytest
from homeassistant.components import automation from homeassistant.components import automation
from homeassistant.components.bluetooth.const import DOMAIN as BLUETOOTH_DOMAIN from homeassistant.components.bluetooth.const import DOMAIN as BLUETOOTH_DOMAIN
from homeassistant.components.bthome.const import CONF_SUBTYPE, DOMAIN from homeassistant.components.bthome.const import CONF_SUBTYPE, DOMAIN
@ -20,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
@ -31,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_bthome_device(hass, mac: str): async def _async_setup_bthome_device(hass, mac: str):
config_entry = MockConfigEntry( config_entry = MockConfigEntry(
domain=DOMAIN, domain=DOMAIN,
@ -230,7 +221,7 @@ async def test_get_triggers_for_invalid_device_id(hass: HomeAssistant) -> None:
async def test_if_fires_on_motion_detected( async def test_if_fires_on_motion_detected(
hass: HomeAssistant, calls: list[ServiceCall] hass: HomeAssistant, 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"
@ -278,8 +269,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_button_long_press" assert service_calls[0].data["some"] == "test_trigger_button_long_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()