mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Add type hints to hdmi_cec assert_state function (#118940)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
parent
29952d8128
commit
622a69447d
@ -1,5 +1,7 @@
|
|||||||
"""Tests for the HDMI-CEC media player platform."""
|
"""Tests for the HDMI-CEC media player platform."""
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
|
||||||
from pycec.const import (
|
from pycec.const import (
|
||||||
DEVICE_TYPE_NAMES,
|
DEVICE_TYPE_NAMES,
|
||||||
KEY_BACKWARD,
|
KEY_BACKWARD,
|
||||||
@ -54,6 +56,8 @@ from homeassistant.core import HomeAssistant
|
|||||||
|
|
||||||
from . import MockHDMIDevice, assert_key_press_release
|
from . import MockHDMIDevice, assert_key_press_release
|
||||||
|
|
||||||
|
type AssertState = Callable[[str, str], None]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(
|
@pytest.fixture(
|
||||||
name="assert_state",
|
name="assert_state",
|
||||||
@ -70,20 +74,20 @@ from . import MockHDMIDevice, assert_key_press_release
|
|||||||
],
|
],
|
||||||
ids=["skip_assert_state", "run_assert_state"],
|
ids=["skip_assert_state", "run_assert_state"],
|
||||||
)
|
)
|
||||||
def assert_state_fixture(request: pytest.FixtureRequest):
|
def assert_state_fixture(request: pytest.FixtureRequest) -> AssertState:
|
||||||
"""Allow for skipping the assert state changes.
|
"""Allow for skipping the assert state changes.
|
||||||
|
|
||||||
This is broken in this entity, but we still want to test that
|
This is broken in this entity, but we still want to test that
|
||||||
the rest of the code works as expected.
|
the rest of the code works as expected.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def test_state(state, expected):
|
def _test_state(state: str, expected: str) -> None:
|
||||||
if request.param:
|
if request.param:
|
||||||
assert state == expected
|
assert state == expected
|
||||||
else:
|
else:
|
||||||
assert True
|
assert True
|
||||||
|
|
||||||
return test_state
|
return _test_state
|
||||||
|
|
||||||
|
|
||||||
async def test_load_platform(
|
async def test_load_platform(
|
||||||
@ -128,7 +132,10 @@ async def test_load_types(
|
|||||||
|
|
||||||
|
|
||||||
async def test_service_on(
|
async def test_service_on(
|
||||||
hass: HomeAssistant, create_hdmi_network, create_cec_entity, assert_state
|
hass: HomeAssistant,
|
||||||
|
create_hdmi_network,
|
||||||
|
create_cec_entity,
|
||||||
|
assert_state: AssertState,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that media_player triggers on `on` service."""
|
"""Test that media_player triggers on `on` service."""
|
||||||
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
||||||
@ -152,7 +159,10 @@ async def test_service_on(
|
|||||||
|
|
||||||
|
|
||||||
async def test_service_off(
|
async def test_service_off(
|
||||||
hass: HomeAssistant, create_hdmi_network, create_cec_entity, assert_state
|
hass: HomeAssistant,
|
||||||
|
create_hdmi_network,
|
||||||
|
create_cec_entity,
|
||||||
|
assert_state: AssertState,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that media_player triggers on `off` service."""
|
"""Test that media_player triggers on `off` service."""
|
||||||
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
||||||
@ -352,10 +362,10 @@ async def test_playback_services(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
create_hdmi_network,
|
create_hdmi_network,
|
||||||
create_cec_entity,
|
create_cec_entity,
|
||||||
assert_state,
|
assert_state: AssertState,
|
||||||
service,
|
service: str,
|
||||||
key,
|
key: int,
|
||||||
expected_state,
|
expected_state: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test playback related commands."""
|
"""Test playback related commands."""
|
||||||
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
||||||
@ -382,7 +392,7 @@ async def test_play_pause_service(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
create_hdmi_network,
|
create_hdmi_network,
|
||||||
create_cec_entity,
|
create_cec_entity,
|
||||||
assert_state,
|
assert_state: AssertState,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test play pause service."""
|
"""Test play pause service."""
|
||||||
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
hdmi_network = await create_hdmi_network({"platform": "media_player"})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user