Improve type hints in group tests (#121174)

This commit is contained in:
epenet 2024-07-04 10:22:39 +02:00 committed by GitHub
parent d55d02623a
commit 4589be2d11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 26 deletions

View File

@ -2,6 +2,7 @@
import asyncio import asyncio
from datetime import timedelta from datetime import timedelta
from typing import Any
import pytest import pytest
@ -90,7 +91,9 @@ CONFIG_ATTRIBUTES = {
@pytest.fixture @pytest.fixture
async def setup_comp(hass, config_count): async def setup_comp(
hass: HomeAssistant, config_count: tuple[dict[str, Any], int]
) -> None:
"""Set up group cover component.""" """Set up group cover component."""
config, count = config_count config, count = config_count
with assert_setup_component(count, DOMAIN): with assert_setup_component(count, DOMAIN):
@ -101,7 +104,8 @@ async def setup_comp(hass, config_count):
@pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)])
async def test_state(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_state(hass: HomeAssistant) -> None:
"""Test handling of state. """Test handling of state.
The group state is unknown if all group members are unknown or unavailable. The group state is unknown if all group members are unknown or unavailable.
@ -250,8 +254,9 @@ async def test_state(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)])
@pytest.mark.usefixtures("setup_comp")
async def test_attributes( async def test_attributes(
hass: HomeAssistant, entity_registry: er.EntityRegistry, setup_comp hass: HomeAssistant, entity_registry: er.EntityRegistry
) -> None: ) -> None:
"""Test handling of state attributes.""" """Test handling of state attributes."""
state = hass.states.get(COVER_GROUP) state = hass.states.get(COVER_GROUP)
@ -416,9 +421,8 @@ async def test_attributes(
@pytest.mark.parametrize("config_count", [(CONFIG_TILT_ONLY, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_TILT_ONLY, 2)])
async def test_cover_that_only_supports_tilt_removed( @pytest.mark.usefixtures("setup_comp")
hass: HomeAssistant, setup_comp async def test_cover_that_only_supports_tilt_removed(hass: HomeAssistant) -> None:
) -> None:
"""Test removing a cover that support tilt.""" """Test removing a cover that support tilt."""
hass.states.async_set( hass.states.async_set(
DEMO_COVER_TILT, DEMO_COVER_TILT,
@ -446,7 +450,8 @@ async def test_cover_that_only_supports_tilt_removed(
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_open_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_open_covers(hass: HomeAssistant) -> None:
"""Test open cover function.""" """Test open cover function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
@ -467,7 +472,8 @@ async def test_open_covers(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_close_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_close_covers(hass: HomeAssistant) -> None:
"""Test close cover function.""" """Test close cover function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
@ -488,7 +494,8 @@ async def test_close_covers(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_toggle_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_toggle_covers(hass: HomeAssistant) -> None:
"""Test toggle cover function.""" """Test toggle cover function."""
# Start covers in open state # Start covers in open state
await hass.services.async_call( await hass.services.async_call(
@ -538,7 +545,8 @@ async def test_toggle_covers(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_stop_covers(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_stop_covers(hass: HomeAssistant) -> None:
"""Test stop cover function.""" """Test stop cover function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
@ -564,7 +572,8 @@ async def test_stop_covers(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_set_cover_position(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_set_cover_position(hass: HomeAssistant) -> None:
"""Test set cover position function.""" """Test set cover position function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, DOMAIN,
@ -587,7 +596,8 @@ async def test_set_cover_position(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_open_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_open_tilts(hass: HomeAssistant) -> None:
"""Test open tilt function.""" """Test open tilt function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
@ -607,7 +617,8 @@ async def test_open_tilts(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_close_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_close_tilts(hass: HomeAssistant) -> None:
"""Test close tilt function.""" """Test close tilt function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_CLOSE_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
@ -625,7 +636,8 @@ async def test_close_tilts(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_toggle_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_toggle_tilts(hass: HomeAssistant) -> None:
"""Test toggle tilt function.""" """Test toggle tilt function."""
# Start tilted open # Start tilted open
await hass.services.async_call( await hass.services.async_call(
@ -678,7 +690,8 @@ async def test_toggle_tilts(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_stop_tilts(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_stop_tilts(hass: HomeAssistant) -> None:
"""Test stop tilts function.""" """Test stop tilts function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_OPEN_COVER_TILT, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True
@ -702,7 +715,8 @@ async def test_stop_tilts(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_ALL, 2)])
async def test_set_tilt_positions(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_set_tilt_positions(hass: HomeAssistant) -> None:
"""Test set tilt position function.""" """Test set tilt position function."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, DOMAIN,
@ -723,7 +737,8 @@ async def test_set_tilt_positions(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_POS, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_POS, 2)])
async def test_is_opening_closing(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_is_opening_closing(hass: HomeAssistant) -> None:
"""Test is_opening property.""" """Test is_opening property."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: COVER_GROUP}, blocking=True

View File

@ -1,6 +1,7 @@
"""The tests for the group fan platform.""" """The tests for the group fan platform."""
import asyncio import asyncio
from typing import Any
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@ -102,7 +103,9 @@ CONFIG_ATTRIBUTES = {
@pytest.fixture @pytest.fixture
async def setup_comp(hass, config_count): async def setup_comp(
hass: HomeAssistant, config_count: tuple[dict[str, Any], int]
) -> None:
"""Set up group fan component.""" """Set up group fan component."""
config, count = config_count config, count = config_count
with assert_setup_component(count, DOMAIN): with assert_setup_component(count, DOMAIN):
@ -113,9 +116,8 @@ async def setup_comp(hass, config_count):
@pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)])
async def test_state( @pytest.mark.usefixtures("setup_comp")
hass: HomeAssistant, entity_registry: er.EntityRegistry, setup_comp async def test_state(hass: HomeAssistant, entity_registry: er.EntityRegistry) -> None:
) -> None:
"""Test handling of state. """Test handling of state.
The group state is on if at least one group member is on. The group state is on if at least one group member is on.
@ -210,7 +212,8 @@ async def test_state(
@pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)]) @pytest.mark.parametrize("config_count", [(CONFIG_ATTRIBUTES, 1)])
async def test_attributes(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_attributes(hass: HomeAssistant) -> None:
"""Test handling of state attributes.""" """Test handling of state attributes."""
state = hass.states.get(FAN_GROUP) state = hass.states.get(FAN_GROUP)
assert state.state == STATE_UNAVAILABLE assert state.state == STATE_UNAVAILABLE
@ -267,7 +270,8 @@ async def test_attributes(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_FULL_SUPPORT, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_FULL_SUPPORT, 2)])
async def test_direction_oscillating(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_direction_oscillating(hass: HomeAssistant) -> None:
"""Test handling of direction and oscillating attributes.""" """Test handling of direction and oscillating attributes."""
hass.states.async_set( hass.states.async_set(
@ -378,7 +382,8 @@ async def test_direction_oscillating(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_MISSING_FAN, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_MISSING_FAN, 2)])
async def test_state_missing_entity_id(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_state_missing_entity_id(hass: HomeAssistant) -> None:
"""Test we can still setup with a missing entity id.""" """Test we can still setup with a missing entity id."""
state = hass.states.get(FAN_GROUP) state = hass.states.get(FAN_GROUP)
await hass.async_block_till_done() await hass.async_block_till_done()
@ -398,7 +403,8 @@ async def test_setup_before_started(hass: HomeAssistant) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_MISSING_FAN, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_MISSING_FAN, 2)])
async def test_reload(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_reload(hass: HomeAssistant) -> None:
"""Test the ability to reload fans.""" """Test the ability to reload fans."""
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_start() await hass.async_start()
@ -421,7 +427,8 @@ async def test_reload(hass: HomeAssistant, setup_comp) -> None:
@pytest.mark.parametrize("config_count", [(CONFIG_FULL_SUPPORT, 2)]) @pytest.mark.parametrize("config_count", [(CONFIG_FULL_SUPPORT, 2)])
async def test_service_calls(hass: HomeAssistant, setup_comp) -> None: @pytest.mark.usefixtures("setup_comp")
async def test_service_calls(hass: HomeAssistant) -> None:
"""Test calling services.""" """Test calling services."""
await hass.services.async_call( await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: FAN_GROUP}, blocking=True DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: FAN_GROUP}, blocking=True