Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions tests/components/template/test_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import datetime as dt
from unittest.mock import patch

import pytest

from homeassistant import setup
from homeassistant.components.button.const import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
from homeassistant.components.template.button import DEFAULT_NAME
Expand All @@ -16,19 +14,13 @@
)
from homeassistant.helpers.entity_registry import async_get

from tests.common import assert_setup_component, async_mock_service
from tests.common import assert_setup_component

_TEST_BUTTON = "button.template_button"
_TEST_OPTIONS_BUTTON = "button.test"


@pytest.fixture
def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")


async def test_missing_optional_config(hass, calls):
async def test_missing_optional_config(hass):
"""Test: missing optional template is ok."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand All @@ -50,7 +42,7 @@ async def test_missing_optional_config(hass, calls):
_verify(hass, STATE_UNKNOWN)


async def test_missing_required_keys(hass, calls):
async def test_missing_required_keys(hass):
"""Test: missing required fields will fail."""
with assert_setup_component(0, "template"):
assert await setup.async_setup_component(
Expand Down Expand Up @@ -128,7 +120,7 @@ async def test_all_optional_config(hass, calls):
assert er.async_get_entity_id("button", "template", "test-test")


async def test_name_template(hass, calls):
async def test_name_template(hass):
"""Test: name template."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand Down Expand Up @@ -158,7 +150,7 @@ async def test_name_template(hass, calls):
)


async def test_unique_id(hass, calls):
async def test_unique_id(hass):
"""Test: unique id is ok."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand Down
2 changes: 1 addition & 1 deletion tests/components/template/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ async def test_on_off(hass):
_verify(hass, state, 0, None, None, None)


async def test_set_invalid_direction_from_initial_stage(hass, calls):
async def test_set_invalid_direction_from_initial_stage(hass):
"""Test set invalid direction when fan is in initial state."""
await _register_components(hass)

Expand Down
21 changes: 5 additions & 16 deletions tests/components/template/test_number.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""The tests for the Template number platform."""
import pytest

from homeassistant import setup
from homeassistant.components.input_number import (
Expand All @@ -19,11 +18,7 @@
from homeassistant.core import Context
from homeassistant.helpers.entity_registry import async_get

from tests.common import (
assert_setup_component,
async_capture_events,
async_mock_service,
)
from tests.common import assert_setup_component, async_capture_events

_TEST_NUMBER = "number.template_number"
# Represent for number's value
Expand All @@ -47,13 +42,7 @@
}


@pytest.fixture
def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")


async def test_missing_optional_config(hass, calls):
async def test_missing_optional_config(hass):
"""Test: missing optional template is ok."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand All @@ -77,7 +66,7 @@ async def test_missing_optional_config(hass, calls):
_verify(hass, 4, 1, 0.0, 100.0)


async def test_missing_required_keys(hass, calls):
async def test_missing_required_keys(hass):
"""Test: missing required fields will fail."""
with assert_setup_component(0, "template"):
assert await setup.async_setup_component(
Expand Down Expand Up @@ -112,7 +101,7 @@ async def test_missing_required_keys(hass, calls):
assert hass.states.async_all("number") == []


async def test_all_optional_config(hass, calls):
async def test_all_optional_config(hass):
"""Test: including all optional templates is ok."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand All @@ -138,7 +127,7 @@ async def test_all_optional_config(hass, calls):
_verify(hass, 4, 1, 3, 5)


async def test_templates_with_entities(hass, calls):
async def test_templates_with_entities(hass):
"""Test templates with values from other entities."""
with assert_setup_component(4, "input_number"):
assert await setup.async_setup_component(
Expand Down
24 changes: 6 additions & 18 deletions tests/components/template/test_select.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""The tests for the Template select platform."""
import pytest

from homeassistant import setup
from homeassistant.components.input_select import (
ATTR_OPTION as INPUT_SELECT_ATTR_OPTION,
Expand All @@ -19,24 +17,14 @@
from homeassistant.core import Context
from homeassistant.helpers.entity_registry import async_get

from tests.common import (
assert_setup_component,
async_capture_events,
async_mock_service,
)
from tests.common import assert_setup_component, async_capture_events

_TEST_SELECT = "select.template_select"
# Represent for select's current_option
_OPTION_INPUT_SELECT = "input_select.option"


@pytest.fixture
def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation")


async def test_missing_optional_config(hass, calls):
async def test_missing_optional_config(hass):
"""Test: missing optional template is ok."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand All @@ -60,7 +48,7 @@ async def test_missing_optional_config(hass, calls):
_verify(hass, "a", ["a", "b"])


async def test_multiple_configs(hass, calls):
async def test_multiple_configs(hass):
"""Test: multiple select entities get created."""
with assert_setup_component(1, "template"):
assert await setup.async_setup_component(
Expand Down Expand Up @@ -92,7 +80,7 @@ async def test_multiple_configs(hass, calls):
_verify(hass, "a", ["a", "b"], f"{_TEST_SELECT}_2")


async def test_missing_required_keys(hass, calls):
async def test_missing_required_keys(hass):
"""Test: missing required fields will fail."""
with assert_setup_component(0, "template"):
assert await setup.async_setup_component(
Expand Down Expand Up @@ -143,7 +131,7 @@ async def test_missing_required_keys(hass, calls):
assert hass.states.async_all("select") == []


async def test_templates_with_entities(hass, calls):
async def test_templates_with_entities(hass):
"""Test templates with values from other entities."""
with assert_setup_component(1, "input_select"):
assert await setup.async_setup_component(
Expand Down Expand Up @@ -290,7 +278,7 @@ def _verify(hass, expected_current_option, expected_options, entity_name=_TEST_S
assert attributes.get(SELECT_ATTR_OPTIONS) == expected_options


async def test_template_icon_with_entities(hass, calls):
async def test_template_icon_with_entities(hass):
"""Test templates with values from other entities."""
with assert_setup_component(1, "input_select"):
assert await setup.async_setup_component(
Expand Down