Add monkeypatch type hints to rflink tests (#121053)

This commit is contained in:
epenet 2024-07-05 10:54:16 +02:00 committed by GitHub
parent 0cf5b4f965
commit 2ab02c06c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 178 additions and 59 deletions

View file

@ -5,6 +5,8 @@ automatic sensor creation.
"""
import pytest
from homeassistant.components.rflink import (
CONF_RECONNECT_INTERVAL,
DATA_ENTITY_LOOKUP,
@ -39,7 +41,9 @@ CONFIG = {
}
async def test_default_setup(hass: HomeAssistant, monkeypatch) -> None:
async def test_default_setup(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Test all basic functionality of the rflink sensor component."""
# setup mocking rflink module
event_callback, create, _, _ = await mock_rflink(hass, CONFIG, DOMAIN, monkeypatch)
@ -100,7 +104,9 @@ async def test_default_setup(hass: HomeAssistant, monkeypatch) -> None:
assert bat_sensor.attributes[ATTR_ICON] == "mdi:battery"
async def test_disable_automatic_add(hass: HomeAssistant, monkeypatch) -> None:
async def test_disable_automatic_add(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
) -> None:
"""If disabled new devices should not be automatically added."""
config = {
"rflink": {"port": "/dev/ttyABC0"},
@ -125,7 +131,9 @@ async def test_disable_automatic_add(hass: HomeAssistant, monkeypatch) -> None:
assert not hass.states.get("sensor.test2")
async def test_entity_availability(hass: HomeAssistant, monkeypatch) -> None:
async def test_entity_availability(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
) -> None:
"""If Rflink device is disconnected, entities should become unavailable."""
# Make sure Rflink mock does not 'recover' to quickly from the
# disconnect or else the unavailability cannot be measured
@ -160,7 +168,7 @@ async def test_entity_availability(hass: HomeAssistant, monkeypatch) -> None:
assert hass.states.get("sensor.test").state == STATE_UNKNOWN
async def test_aliases(hass: HomeAssistant, monkeypatch) -> None:
async def test_aliases(hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch) -> None:
"""Validate the response to sensor's alias (with aliases)."""
config = {
"rflink": {"port": "/dev/ttyABC0"},
@ -202,7 +210,9 @@ async def test_aliases(hass: HomeAssistant, monkeypatch) -> None:
assert updated_sensor.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
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."""
config = {"rflink": {"port": "/dev/ttyABC0"}, DOMAIN: {"platform": "rflink"}}
tmp_entity = TMP_ENTITY.format("test3")
@ -241,7 +251,9 @@ async def test_race_condition(hass: HomeAssistant, monkeypatch) -> None:
assert new_sensor.state == "ko"
async def test_sensor_attributes(hass: HomeAssistant, monkeypatch) -> None:
async def test_sensor_attributes(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Validate the sensor attributes."""
config = {