Add type hints to integration tests (part 18) (#88174)
This commit is contained in:
parent
f465561536
commit
0a80ac19bc
47 changed files with 494 additions and 272 deletions
|
@ -15,7 +15,7 @@ from homeassistant.const import (
|
|||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
from homeassistant.core import CoreState, HomeAssistant, State, callback
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .test_init import mock_rflink
|
||||
|
@ -44,7 +44,7 @@ CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_default_setup(hass, monkeypatch):
|
||||
async def test_default_setup(hass: HomeAssistant, 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)
|
||||
|
@ -83,7 +83,7 @@ async def test_default_setup(hass, monkeypatch):
|
|||
assert hass.states.get("binary_sensor.test").state == STATE_OFF
|
||||
|
||||
|
||||
async def test_entity_availability(hass, monkeypatch):
|
||||
async def test_entity_availability(hass: HomeAssistant, 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
|
||||
|
@ -124,7 +124,7 @@ async def test_entity_availability(hass, monkeypatch):
|
|||
assert hass.states.get("binary_sensor.test").state == STATE_ON
|
||||
|
||||
|
||||
async def test_off_delay(hass, monkeypatch):
|
||||
async def test_off_delay(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test off_delay option."""
|
||||
# setup mocking rflink module
|
||||
event_callback, create, _, _ = await mock_rflink(hass, CONFIG, DOMAIN, monkeypatch)
|
||||
|
@ -187,7 +187,7 @@ async def test_off_delay(hass, monkeypatch):
|
|||
assert len(events) == 3
|
||||
|
||||
|
||||
async def test_restore_state(hass, monkeypatch):
|
||||
async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Ensure states are restored on startup."""
|
||||
mock_restore_cache(
|
||||
hass, (State(f"{DOMAIN}.test", STATE_ON), State(f"{DOMAIN}.test2", STATE_ON))
|
||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.const import (
|
|||
STATE_CLOSED,
|
||||
STATE_OPEN,
|
||||
)
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
from homeassistant.core import CoreState, HomeAssistant, State, callback
|
||||
|
||||
from .test_init import mock_rflink
|
||||
|
||||
|
@ -36,7 +36,7 @@ CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_default_setup(hass, monkeypatch):
|
||||
async def test_default_setup(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test all basic functionality of the RFLink cover component."""
|
||||
# setup mocking rflink module
|
||||
event_callback, create, protocol, _ = await mock_rflink(
|
||||
|
@ -106,7 +106,7 @@ async def test_default_setup(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_args_list[1][0][1] == "UP"
|
||||
|
||||
|
||||
async def test_firing_bus_event(hass, monkeypatch):
|
||||
async def test_firing_bus_event(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Incoming RFLink command events should be put on the HA event bus."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -141,7 +141,7 @@ async def test_firing_bus_event(hass, monkeypatch):
|
|||
assert calls[0].data == {"state": "down", "entity_id": f"{DOMAIN}.test"}
|
||||
|
||||
|
||||
async def test_signal_repetitions(hass, monkeypatch):
|
||||
async def test_signal_repetitions(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Command should be sent amount of configured repetitions."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -179,7 +179,7 @@ async def test_signal_repetitions(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_count == 5
|
||||
|
||||
|
||||
async def test_signal_repetitions_alternation(hass, monkeypatch):
|
||||
async def test_signal_repetitions_alternation(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Simultaneously switching entities must alternate repetitions."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -210,7 +210,7 @@ async def test_signal_repetitions_alternation(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_args_list[3][0][0] == "protocol_0_1"
|
||||
|
||||
|
||||
async def test_signal_repetitions_cancelling(hass, monkeypatch):
|
||||
async def test_signal_repetitions_cancelling(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Cancel outstanding repetitions when state changed."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -239,7 +239,7 @@ async def test_signal_repetitions_cancelling(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_args_list[3][0][1] == "UP"
|
||||
|
||||
|
||||
async def test_group_alias(hass, monkeypatch):
|
||||
async def test_group_alias(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -269,7 +269,7 @@ async def test_group_alias(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
|
||||
|
||||
|
||||
async def test_nogroup_alias(hass, monkeypatch):
|
||||
async def test_nogroup_alias(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Non group aliases should not respond to group commands."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -302,7 +302,7 @@ async def test_nogroup_alias(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
|
||||
|
||||
|
||||
async def test_nogroup_device_id(hass, monkeypatch):
|
||||
async def test_nogroup_device_id(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -330,7 +330,7 @@ async def test_nogroup_device_id(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
|
||||
|
||||
|
||||
async def test_restore_state(hass, monkeypatch):
|
||||
async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Ensure states are restored on startup."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -376,7 +376,7 @@ async def test_restore_state(hass, monkeypatch):
|
|||
# The code checks the ID, it will use the
|
||||
# 'inverted' class when the name starts with
|
||||
# 'newkaku'
|
||||
async def test_inverted_cover(hass, monkeypatch):
|
||||
async def test_inverted_cover(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Ensure states are restored on startup."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.const import (
|
|||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
from homeassistant.core import CoreState, HomeAssistant, State, callback
|
||||
|
||||
from .test_init import mock_rflink
|
||||
|
||||
|
@ -37,7 +37,7 @@ CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_default_setup(hass, monkeypatch):
|
||||
async def test_default_setup(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test all basic functionality of the RFLink switch component."""
|
||||
# setup mocking rflink module
|
||||
event_callback, create, protocol, _ = await mock_rflink(
|
||||
|
@ -145,7 +145,7 @@ async def test_default_setup(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_args_list[5][0][1] == "7"
|
||||
|
||||
|
||||
async def test_firing_bus_event(hass, monkeypatch):
|
||||
async def test_firing_bus_event(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Incoming RFLink command events should be put on the HA event bus."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -180,7 +180,7 @@ async def test_firing_bus_event(hass, monkeypatch):
|
|||
assert calls[0].data == {"state": "off", "entity_id": f"{DOMAIN}.test"}
|
||||
|
||||
|
||||
async def test_signal_repetitions(hass, monkeypatch):
|
||||
async def test_signal_repetitions(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Command should be sent amount of configured repetitions."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -236,7 +236,7 @@ async def test_signal_repetitions(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_count == 8
|
||||
|
||||
|
||||
async def test_signal_repetitions_alternation(hass, monkeypatch):
|
||||
async def test_signal_repetitions_alternation(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Simultaneously switching entities must alternate repetitions."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -267,7 +267,7 @@ async def test_signal_repetitions_alternation(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_args_list[3][0][0] == "protocol_0_1"
|
||||
|
||||
|
||||
async def test_signal_repetitions_cancelling(hass, monkeypatch):
|
||||
async def test_signal_repetitions_cancelling(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Cancel outstanding repetitions when state changed."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -296,7 +296,7 @@ async def test_signal_repetitions_cancelling(hass, monkeypatch):
|
|||
]
|
||||
|
||||
|
||||
async def test_type_toggle(hass, monkeypatch):
|
||||
async def test_type_toggle(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test toggle type lights (on/on)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -341,7 +341,7 @@ async def test_type_toggle(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "off"
|
||||
|
||||
|
||||
async def test_set_level_command(hass, monkeypatch):
|
||||
async def test_set_level_command(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test 'set_level=XX' events."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -428,7 +428,7 @@ async def test_set_level_command(hass, monkeypatch):
|
|||
assert state.attributes[ATTR_BRIGHTNESS] == 0
|
||||
|
||||
|
||||
async def test_group_alias(hass, monkeypatch):
|
||||
async def test_group_alias(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -465,7 +465,7 @@ async def test_group_alias(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test2").state == "on"
|
||||
|
||||
|
||||
async def test_nogroup_alias(hass, monkeypatch):
|
||||
async def test_nogroup_alias(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Non group aliases should not respond to group commands."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -498,7 +498,7 @@ async def test_nogroup_alias(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == "on"
|
||||
|
||||
|
||||
async def test_nogroup_device_id(hass, monkeypatch):
|
||||
async def test_nogroup_device_id(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -526,7 +526,7 @@ async def test_nogroup_device_id(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == "on"
|
||||
|
||||
|
||||
async def test_disable_automatic_add(hass, monkeypatch):
|
||||
async def test_disable_automatic_add(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""If disabled new devices should not be automatically added."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -544,7 +544,7 @@ async def test_disable_automatic_add(hass, monkeypatch):
|
|||
assert not hass.states.get(f"{DOMAIN}.protocol_0_0")
|
||||
|
||||
|
||||
async def test_restore_state(hass, monkeypatch):
|
||||
async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Ensure states are restored on startup."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
|
|
@ -4,7 +4,6 @@ Test setup of rflink sensor component/platform. Verify manual and
|
|||
automatic sensor creation.
|
||||
|
||||
"""
|
||||
|
||||
from homeassistant.components.rflink import (
|
||||
CONF_RECONNECT_INTERVAL,
|
||||
DATA_ENTITY_LOOKUP,
|
||||
|
@ -21,6 +20,7 @@ from homeassistant.const import (
|
|||
UnitOfPrecipitationDepth,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .test_init import mock_rflink
|
||||
|
||||
|
@ -38,7 +38,7 @@ CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_default_setup(hass, monkeypatch):
|
||||
async def test_default_setup(hass: HomeAssistant, 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)
|
||||
|
@ -99,7 +99,7 @@ async def test_default_setup(hass, monkeypatch):
|
|||
assert bat_sensor.attributes[ATTR_ICON] == "mdi:battery"
|
||||
|
||||
|
||||
async def test_disable_automatic_add(hass, monkeypatch):
|
||||
async def test_disable_automatic_add(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""If disabled new devices should not be automatically added."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -124,7 +124,7 @@ async def test_disable_automatic_add(hass, monkeypatch):
|
|||
assert not hass.states.get("sensor.test2")
|
||||
|
||||
|
||||
async def test_entity_availability(hass, monkeypatch):
|
||||
async def test_entity_availability(hass: HomeAssistant, 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
|
||||
|
@ -159,7 +159,7 @@ async def test_entity_availability(hass, monkeypatch):
|
|||
assert hass.states.get("sensor.test").state == STATE_UNKNOWN
|
||||
|
||||
|
||||
async def test_aliases(hass, monkeypatch):
|
||||
async def test_aliases(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Validate the response to sensor's alias (with aliases)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -201,7 +201,7 @@ async def test_aliases(hass, monkeypatch):
|
|||
assert updated_sensor.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
|
||||
|
||||
|
||||
async def test_race_condition(hass, monkeypatch):
|
||||
async def test_race_condition(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test race condition for unknown components."""
|
||||
config = {"rflink": {"port": "/dev/ttyABC0"}, DOMAIN: {"platform": "rflink"}}
|
||||
tmp_entity = TMP_ENTITY.format("test3")
|
||||
|
@ -240,7 +240,7 @@ async def test_race_condition(hass, monkeypatch):
|
|||
assert new_sensor.state == "ko"
|
||||
|
||||
|
||||
async def test_sensor_attributes(hass, monkeypatch):
|
||||
async def test_sensor_attributes(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Validate the sensor attributes."""
|
||||
|
||||
config = {
|
||||
|
|
|
@ -4,7 +4,6 @@ Test setup of rflink switch component/platform. State tracking and
|
|||
control of Rflink switch devices.
|
||||
|
||||
"""
|
||||
|
||||
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
|
@ -13,7 +12,7 @@ from homeassistant.const import (
|
|||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import CoreState, State, callback
|
||||
from homeassistant.core import CoreState, HomeAssistant, State, callback
|
||||
|
||||
from .test_init import mock_rflink
|
||||
|
||||
|
@ -33,7 +32,7 @@ CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def test_default_setup(hass, monkeypatch):
|
||||
async def test_default_setup(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test all basic functionality of the rflink switch component."""
|
||||
# setup mocking rflink module
|
||||
event_callback, create, protocol, _ = await mock_rflink(
|
||||
|
@ -93,7 +92,7 @@ async def test_default_setup(hass, monkeypatch):
|
|||
assert protocol.send_command_ack.call_args_list[1][0][1] == "on"
|
||||
|
||||
|
||||
async def test_group_alias(hass, monkeypatch):
|
||||
async def test_group_alias(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -123,7 +122,7 @@ async def test_group_alias(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == "on"
|
||||
|
||||
|
||||
async def test_nogroup_alias(hass, monkeypatch):
|
||||
async def test_nogroup_alias(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Non group aliases should not respond to group commands."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -156,7 +155,7 @@ async def test_nogroup_alias(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == "on"
|
||||
|
||||
|
||||
async def test_nogroup_device_id(hass, monkeypatch):
|
||||
async def test_nogroup_device_id(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -184,7 +183,7 @@ async def test_nogroup_device_id(hass, monkeypatch):
|
|||
assert hass.states.get(f"{DOMAIN}.test").state == "on"
|
||||
|
||||
|
||||
async def test_device_defaults(hass, monkeypatch):
|
||||
async def test_device_defaults(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Event should fire if device_defaults config says so."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -216,7 +215,7 @@ async def test_device_defaults(hass, monkeypatch):
|
|||
assert calls[0].data == {"state": "off", "entity_id": f"{DOMAIN}.test"}
|
||||
|
||||
|
||||
async def test_not_firing_default(hass, monkeypatch):
|
||||
async def test_not_firing_default(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""By default no bus events should be fired."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
@ -246,7 +245,7 @@ async def test_not_firing_default(hass, monkeypatch):
|
|||
assert not calls, "an event has been fired"
|
||||
|
||||
|
||||
async def test_restore_state(hass, monkeypatch):
|
||||
async def test_restore_state(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Ensure states are restored on startup."""
|
||||
config = {
|
||||
"rflink": {"port": "/dev/ttyABC0"},
|
||||
|
|
|
@ -3,9 +3,10 @@ from homeassistant.components.rflink.utils import (
|
|||
brightness_to_rflink,
|
||||
rflink_to_brightness,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
async def test_utils(hass, monkeypatch):
|
||||
async def test_utils(hass: HomeAssistant, monkeypatch) -> None:
|
||||
"""Test all utils methods."""
|
||||
# test brightness_to_rflink
|
||||
assert brightness_to_rflink(0) == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue