diff --git a/script/scaffold/templates/device_condition/tests/test_device_condition.py b/script/scaffold/templates/device_condition/tests/test_device_condition.py index ad6d527bd65..5a0e7122571 100644 --- a/script/scaffold/templates/device_condition/tests/test_device_condition.py +++ b/script/scaffold/templates/device_condition/tests/test_device_condition.py @@ -2,7 +2,6 @@ from __future__ import annotations -import pytest from pytest_unordered import unordered from homeassistant.components import automation @@ -13,17 +12,7 @@ from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component -from tests.common import ( - MockConfigEntry, - async_get_device_automations, - async_mock_service, -) - - -@pytest.fixture -def calls(hass: HomeAssistant) -> list[ServiceCall]: - """Track calls to a mock service.""" - return async_mock_service(hass, "test", "automation") +from tests.common import MockConfigEntry, async_get_device_automations async def test_get_conditions( @@ -63,7 +52,7 @@ async def test_get_conditions( assert conditions == unordered(expected_conditions) -async def test_if_state(hass: HomeAssistant, calls: list[ServiceCall]) -> None: +async def test_if_state(hass: HomeAssistant, service_calls: list[ServiceCall]) -> None: """Test for turn_on and turn_off conditions.""" hass.states.async_set("NEW_DOMAIN.entity", STATE_ON) @@ -114,12 +103,12 @@ async def test_if_state(hass: HomeAssistant, calls: list[ServiceCall]) -> None: hass.bus.async_fire("test_event1") hass.bus.async_fire("test_event2") await hass.async_block_till_done() - assert len(calls) == 1 - assert calls[0].data["some"] == "is_on - event - test_event1" + assert len(service_calls) == 1 + assert service_calls[0].data["some"] == "is_on - event - test_event1" hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF) hass.bus.async_fire("test_event1") hass.bus.async_fire("test_event2") await hass.async_block_till_done() - assert len(calls) == 2 - assert calls[1].data["some"] == "is_off - event - test_event2" + assert len(service_calls) == 2 + assert service_calls[1].data["some"] == "is_off - event - test_event2" diff --git a/script/scaffold/templates/device_trigger/tests/test_device_trigger.py b/script/scaffold/templates/device_trigger/tests/test_device_trigger.py index 54b202c978c..7e4f88261bc 100644 --- a/script/scaffold/templates/device_trigger/tests/test_device_trigger.py +++ b/script/scaffold/templates/device_trigger/tests/test_device_trigger.py @@ -1,6 +1,5 @@ """The tests for NEW_NAME device triggers.""" -import pytest from pytest_unordered import unordered from homeassistant.components import automation @@ -11,17 +10,7 @@ from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.setup import async_setup_component -from tests.common import ( - MockConfigEntry, - async_get_device_automations, - async_mock_service, -) - - -@pytest.fixture -def calls(hass: HomeAssistant) -> list[ServiceCall]: - """Track calls to a mock service.""" - return async_mock_service(hass, "test", "automation") +from tests.common import MockConfigEntry, async_get_device_automations async def test_get_triggers( @@ -62,7 +51,7 @@ async def test_get_triggers( async def test_if_fires_on_state_change( - hass: HomeAssistant, calls: list[ServiceCall] + hass: HomeAssistant, service_calls: list[ServiceCall] ) -> None: """Test for turn_on and turn_off triggers firing.""" hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF) @@ -119,15 +108,15 @@ async def test_if_fires_on_state_change( # Fake that the entity is turning on. hass.states.async_set("NEW_DOMAIN.entity", STATE_ON) await hass.async_block_till_done() - assert len(calls) == 1 - assert calls[0].data[ + assert len(service_calls) == 1 + assert service_calls[0].data[ "some" ] == "turn_on - device - {} - off - on - None - 0".format("NEW_DOMAIN.entity") # Fake that the entity is turning off. hass.states.async_set("NEW_DOMAIN.entity", STATE_OFF) await hass.async_block_till_done() - assert len(calls) == 2 - assert calls[1].data[ + assert len(service_calls) == 2 + assert service_calls[1].data[ "some" ] == "turn_off - device - {} - on - off - None - 0".format("NEW_DOMAIN.entity")