Use direct service calls in tests instead of automation common (#40623)
* Use direct service calls in tests instead of automation common * Remove automation common test helpers
This commit is contained in:
parent
35533407fe
commit
8837ed35cd
11 changed files with 156 additions and 125 deletions
|
@ -2,11 +2,11 @@
|
|||
import pytest
|
||||
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import async_mock_service, mock_component
|
||||
from tests.components.automation import common
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -38,11 +38,15 @@ async def test_if_fires_on_event(hass, calls):
|
|||
|
||||
hass.bus.async_fire("test_event", context=context)
|
||||
await hass.async_block_till_done()
|
||||
assert 1 == len(calls)
|
||||
assert len(calls) == 1
|
||||
assert calls[0].context.parent_id == context.id
|
||||
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
hass.bus.async_fire("test_event")
|
||||
await hass.async_block_till_done()
|
||||
|
@ -66,8 +70,12 @@ async def test_if_fires_on_event_extra_data(hass, calls):
|
|||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
hass.bus.async_fire("test_event")
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -8,6 +8,7 @@ import homeassistant.components.automation as automation
|
|||
from homeassistant.components.homeassistant.triggers import (
|
||||
numeric_state as numeric_state_trigger,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -19,7 +20,6 @@ from tests.common import (
|
|||
async_mock_service,
|
||||
mock_component,
|
||||
)
|
||||
from tests.components.automation import common
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -59,8 +59,13 @@ async def test_if_fires_on_entity_change_below(hass, calls):
|
|||
|
||||
# Set above 12 so the automation will fire again
|
||||
hass.states.async_set("test.entity", 12)
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
hass.states.async_set("test.entity", 9)
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
@ -863,9 +868,12 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
|
|||
hass.states.async_set("test.entity_1", 9)
|
||||
hass.states.async_set("test.entity_2", 9)
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
|
|
@ -5,6 +5,7 @@ import pytest
|
|||
|
||||
import homeassistant.components.automation as automation
|
||||
from homeassistant.components.homeassistant.triggers import state as state_trigger
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
|
||||
from homeassistant.core import Context
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
@ -16,7 +17,6 @@ from tests.common import (
|
|||
async_mock_service,
|
||||
mock_component,
|
||||
)
|
||||
from tests.components.automation import common
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -70,8 +70,12 @@ async def test_if_fires_on_entity_change(hass, calls):
|
|||
assert calls[0].context.parent_id == context.id
|
||||
assert calls[0].data["some"] == "state - test.entity - hello - world - None"
|
||||
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
hass.states.async_set("test.entity", "planet")
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
@ -394,8 +398,12 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
|
|||
hass.states.async_set("test.entity_1", "world")
|
||||
hass.states.async_set("test.entity_2", "world")
|
||||
await hass.async_block_till_done()
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -6,12 +6,12 @@ import voluptuous as vol
|
|||
|
||||
import homeassistant.components.automation as automation
|
||||
import homeassistant.components.homeassistant.triggers.time_pattern as time_pattern
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_MATCH_ALL, SERVICE_TURN_OFF
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import async_fire_time_changed, async_mock_service, mock_component
|
||||
from tests.components.automation import common
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -55,8 +55,12 @@ async def test_if_fires_when_hour_matches(hass, calls):
|
|||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
|
||||
await common.async_turn_off(hass)
|
||||
await hass.async_block_till_done()
|
||||
await hass.services.async_call(
|
||||
automation.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
async_fire_time_changed(hass, now.replace(year=now.year + 1, hour=0))
|
||||
await hass.async_block_till_done()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue