mirror of
https://github.com/home-assistant/core.git
synced 2025-11-15 22:10:09 +00:00
Add monkeypatch type hints to rflink tests (#121053)
This commit is contained in:
@@ -31,7 +31,12 @@ from homeassistant.helpers import entity_registry as er
|
||||
|
||||
|
||||
async def mock_rflink(
|
||||
hass, config, domain, monkeypatch, failures=None, failcommand=False
|
||||
hass: HomeAssistant,
|
||||
config,
|
||||
domain,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
failures=None,
|
||||
failcommand=False,
|
||||
):
|
||||
"""Create mock RFLink asyncio protocol, test component setup."""
|
||||
transport, protocol = (Mock(), Mock())
|
||||
@@ -77,7 +82,9 @@ async def mock_rflink(
|
||||
return event_callback, mock_create, protocol, disconnect_callback
|
||||
|
||||
|
||||
async def test_version_banner(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_version_banner(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test sending unknown commands doesn't cause issues."""
|
||||
# use sensor domain during testing main platform
|
||||
domain = "sensor"
|
||||
@@ -102,7 +109,9 @@ async def test_version_banner(hass: HomeAssistant, monkeypatch) -> None:
|
||||
)
|
||||
|
||||
|
||||
async def test_send_no_wait(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_send_no_wait(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test command sending without ack."""
|
||||
domain = "switch"
|
||||
config = {
|
||||
@@ -126,7 +135,9 @@ async def test_send_no_wait(hass: HomeAssistant, monkeypatch) -> None:
|
||||
assert protocol.send_command.call_args_list[0][0][1] == "off"
|
||||
|
||||
|
||||
async def test_cover_send_no_wait(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_cover_send_no_wait(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test command sending to a cover device without ack."""
|
||||
domain = "cover"
|
||||
config = {
|
||||
@@ -150,7 +161,9 @@ async def test_cover_send_no_wait(hass: HomeAssistant, monkeypatch) -> None:
|
||||
assert protocol.send_command.call_args_list[0][0][1] == "STOP"
|
||||
|
||||
|
||||
async def test_send_command(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_send_command(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test send_command service."""
|
||||
domain = "rflink"
|
||||
config = {"rflink": {"port": "/dev/ttyABC0"}}
|
||||
@@ -168,7 +181,9 @@ async def test_send_command(hass: HomeAssistant, monkeypatch) -> None:
|
||||
assert protocol.send_command_ack.call_args_list[0][0][1] == "on"
|
||||
|
||||
|
||||
async def test_send_command_invalid_arguments(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_send_command_invalid_arguments(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test send_command service."""
|
||||
domain = "rflink"
|
||||
config = {"rflink": {"port": "/dev/ttyABC0"}}
|
||||
@@ -201,7 +216,9 @@ async def test_send_command_invalid_arguments(hass: HomeAssistant, monkeypatch)
|
||||
assert not success, "send command should not succeed for unknown command"
|
||||
|
||||
|
||||
async def test_send_command_event_propagation(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_send_command_event_propagation(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test event propagation for send_command service."""
|
||||
domain = "light"
|
||||
config = {
|
||||
@@ -243,7 +260,9 @@ async def test_send_command_event_propagation(hass: HomeAssistant, monkeypatch)
|
||||
assert hass.states.get(f"{domain}.test1").state == "off"
|
||||
|
||||
|
||||
async def test_reconnecting_after_disconnect(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_reconnecting_after_disconnect(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""An unexpected disconnect should cause a reconnect."""
|
||||
domain = "sensor"
|
||||
config = {
|
||||
@@ -267,7 +286,9 @@ async def test_reconnecting_after_disconnect(hass: HomeAssistant, monkeypatch) -
|
||||
assert mock_create.call_count == 2
|
||||
|
||||
|
||||
async def test_reconnecting_after_failure(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_reconnecting_after_failure(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""A failure to reconnect should be retried."""
|
||||
domain = "sensor"
|
||||
config = {
|
||||
@@ -294,7 +315,9 @@ async def test_reconnecting_after_failure(hass: HomeAssistant, monkeypatch) -> N
|
||||
assert mock_create.call_count == 3
|
||||
|
||||
|
||||
async def test_error_when_not_connected(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_error_when_not_connected(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Sending command should error when not connected."""
|
||||
domain = "switch"
|
||||
config = {
|
||||
@@ -324,7 +347,9 @@ async def test_error_when_not_connected(hass: HomeAssistant, monkeypatch) -> Non
|
||||
assert not success, "changing state should not succeed when disconnected"
|
||||
|
||||
|
||||
async def test_async_send_command_error(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_async_send_command_error(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Sending command should error when protocol fails."""
|
||||
domain = "rflink"
|
||||
config = {"rflink": {"port": "/dev/ttyABC0"}}
|
||||
@@ -345,7 +370,9 @@ async def test_async_send_command_error(hass: HomeAssistant, monkeypatch) -> Non
|
||||
assert protocol.send_command_ack.call_args_list[0][0][1] == SERVICE_TURN_OFF
|
||||
|
||||
|
||||
async def test_race_condition(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_race_condition(
|
||||
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Test race condition for unknown components."""
|
||||
domain = "light"
|
||||
config = {"rflink": {"port": "/dev/ttyABC0"}, domain: {"platform": "rflink"}}
|
||||
@@ -381,7 +408,7 @@ async def test_race_condition(hass: HomeAssistant, monkeypatch) -> None:
|
||||
assert new_sensor.state == "on"
|
||||
|
||||
|
||||
async def test_not_connected(hass: HomeAssistant, monkeypatch) -> None:
|
||||
async def test_not_connected() -> None:
|
||||
"""Test Error when sending commands to a disconnected device."""
|
||||
test_device = RflinkCommand("DUMMY_DEVICE")
|
||||
RflinkCommand.set_rflink_protocol(None)
|
||||
@@ -390,7 +417,9 @@ async def test_not_connected(hass: HomeAssistant, monkeypatch) -> None:
|
||||
|
||||
|
||||
async def test_keepalive(
|
||||
hass: HomeAssistant, monkeypatch, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Validate negative keepalive values."""
|
||||
keepalive_value = -3
|
||||
@@ -418,7 +447,9 @@ async def test_keepalive(
|
||||
|
||||
|
||||
async def test_keepalive_2(
|
||||
hass: HomeAssistant, monkeypatch, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Validate very short keepalive values."""
|
||||
keepalive_value = 30
|
||||
@@ -446,7 +477,9 @@ async def test_keepalive_2(
|
||||
|
||||
|
||||
async def test_keepalive_3(
|
||||
hass: HomeAssistant, monkeypatch, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Validate keepalive=0 value."""
|
||||
domain = RFLINK_DOMAIN
|
||||
@@ -466,7 +499,9 @@ async def test_keepalive_3(
|
||||
|
||||
|
||||
async def test_default_keepalive(
|
||||
hass: HomeAssistant, monkeypatch, caplog: pytest.LogCaptureFixture
|
||||
hass: HomeAssistant,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Validate keepalive=0 value."""
|
||||
domain = RFLINK_DOMAIN
|
||||
@@ -485,7 +520,9 @@ async def test_default_keepalive(
|
||||
|
||||
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry, monkeypatch
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Validate the device unique_id."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user