Add type hints to integration tests (part 5) (#87850)

This commit is contained in:
epenet 2023-02-12 19:39:48 +01:00 committed by GitHub
parent 00c356e1ce
commit 728f62b1ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 563 additions and 332 deletions

View file

@ -15,7 +15,7 @@ from homeassistant.components.device_automation import (
from homeassistant.components.websocket_api.const import TYPE_RESULT
from homeassistant.const import CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.typing import ConfigType
from homeassistant.setup import async_setup_component
@ -94,8 +94,12 @@ def fake_integration(hass):
async def test_websocket_get_actions(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get the expected actions through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -145,8 +149,12 @@ async def test_websocket_get_actions(
async def test_websocket_get_conditions(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get the expected conditions through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -195,8 +203,12 @@ async def test_websocket_get_conditions(
async def test_websocket_get_triggers(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get the expected triggers through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -253,8 +265,12 @@ async def test_websocket_get_triggers(
async def test_websocket_get_action_capabilities(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get the expected action capabilities through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -317,8 +333,11 @@ async def test_websocket_get_action_capabilities(
async def test_websocket_get_action_capabilities_unknown_domain(
hass, hass_ws_client, device_registry, entity_registry
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get no action capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
@ -340,8 +359,12 @@ async def test_websocket_get_action_capabilities_unknown_domain(
async def test_websocket_get_action_capabilities_no_capabilities(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get no action capabilities for a domain which has none.
The tests tests a domain which has a device action platform, but no
@ -367,8 +390,12 @@ async def test_websocket_get_action_capabilities_no_capabilities(
async def test_websocket_get_action_capabilities_bad_action(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get no action capabilities when there is an error."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
@ -397,8 +424,12 @@ async def test_websocket_get_action_capabilities_bad_action(
async def test_websocket_get_condition_capabilities(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get the expected condition capabilities through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -461,8 +492,11 @@ async def test_websocket_get_condition_capabilities(
async def test_websocket_get_condition_capabilities_unknown_domain(
hass, hass_ws_client, device_registry, entity_registry
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get no condition capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
@ -484,8 +518,12 @@ async def test_websocket_get_condition_capabilities_unknown_domain(
async def test_websocket_get_condition_capabilities_no_capabilities(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get no condition capabilities for a domain which has none.
The tests tests a domain which has a device condition platform, but no
@ -515,8 +553,12 @@ async def test_websocket_get_condition_capabilities_no_capabilities(
async def test_websocket_get_condition_capabilities_bad_condition(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get no condition capabilities when there is an error."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
@ -549,8 +591,10 @@ async def test_websocket_get_condition_capabilities_bad_condition(
async def test_async_get_device_automations_single_device_trigger(
hass, device_registry, entity_registry
):
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get can fetch the triggers for a device id."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -570,8 +614,10 @@ async def test_async_get_device_automations_single_device_trigger(
async def test_async_get_device_automations_all_devices_trigger(
hass, device_registry, entity_registry
):
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get can fetch all the triggers when no device id is passed."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -591,8 +637,10 @@ async def test_async_get_device_automations_all_devices_trigger(
async def test_async_get_device_automations_all_devices_condition(
hass, device_registry, entity_registry
):
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get can fetch all the conditions when no device id is passed."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -612,8 +660,10 @@ async def test_async_get_device_automations_all_devices_condition(
async def test_async_get_device_automations_all_devices_action(
hass, device_registry, entity_registry
):
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get can fetch all the actions when no device id is passed."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -633,8 +683,11 @@ async def test_async_get_device_automations_all_devices_action(
async def test_async_get_device_automations_all_devices_action_exception_throw(
hass, device_registry, entity_registry, caplog
):
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test we get can fetch all the actions when no device id is passed and can handle one throwing an exception."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -659,8 +712,12 @@ async def test_async_get_device_automations_all_devices_action_exception_throw(
async def test_websocket_get_trigger_capabilities(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get the expected trigger capabilities through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
@ -723,8 +780,11 @@ async def test_websocket_get_trigger_capabilities(
async def test_websocket_get_trigger_capabilities_unknown_domain(
hass, hass_ws_client, device_registry, entity_registry
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
) -> None:
"""Test we get no trigger capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
@ -746,8 +806,12 @@ async def test_websocket_get_trigger_capabilities_unknown_domain(
async def test_websocket_get_trigger_capabilities_no_capabilities(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get no trigger capabilities for a domain which has none.
The tests tests a domain which has a device trigger platform, but no
@ -777,8 +841,12 @@ async def test_websocket_get_trigger_capabilities_no_capabilities(
async def test_websocket_get_trigger_capabilities_bad_trigger(
hass, hass_ws_client, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test we get no trigger capabilities when there is an error."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
@ -833,7 +901,9 @@ async def test_automation_with_non_existing_integration(
assert "Integration 'beer' not found" in caplog.text
async def test_automation_with_device_action(hass, caplog, fake_integration):
async def test_automation_with_device_action(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, fake_integration
) -> None:
"""Test automation with a device action."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -866,8 +936,11 @@ async def test_automation_with_device_action(hass, caplog, fake_integration):
async def test_automation_with_dynamically_validated_action(
hass, caplog, device_registry, fake_integration
):
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
device_registry: dr.DeviceRegistry,
fake_integration,
) -> None:
"""Test device automation with an action which is dynamically validated."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -919,7 +992,9 @@ async def test_automation_with_integration_without_device_action(
)
async def test_automation_with_device_condition(hass, caplog, fake_integration):
async def test_automation_with_device_condition(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, fake_integration
) -> None:
"""Test automation with a device condition."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -949,8 +1024,11 @@ async def test_automation_with_device_condition(hass, caplog, fake_integration):
async def test_automation_with_dynamically_validated_condition(
hass, caplog, device_registry, fake_integration
):
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
device_registry: dr.DeviceRegistry,
fake_integration,
) -> None:
"""Test device automation with a condition which is dynamically validated."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -1013,7 +1091,9 @@ async def test_automation_with_integration_without_device_condition(
)
async def test_automation_with_device_trigger(hass, caplog, fake_integration):
async def test_automation_with_device_trigger(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, fake_integration
) -> None:
"""Test automation with a device trigger."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -1042,8 +1122,12 @@ async def test_automation_with_device_trigger(hass, caplog, fake_integration):
async def test_automation_with_dynamically_validated_trigger(
hass, caplog, device_registry, entity_registry, fake_integration
):
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
fake_integration,
) -> None:
"""Test device automation with a trigger which is dynamically validated."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -1192,7 +1276,9 @@ def calls(hass):
return async_mock_service(hass, "test", "automation")
async def test_automation_with_sub_condition(hass, calls, enable_custom_integrations):
async def test_automation_with_sub_condition(
hass: HomeAssistant, calls, enable_custom_integrations: None
) -> None:
"""Test automation with device condition under and/or conditions."""
DOMAIN = "light"
platform = getattr(hass.components, f"test.{DOMAIN}")
@ -1360,7 +1446,9 @@ async def test_websocket_device_not_found(
assert msg["error"] == {"code": "not_found", "message": "Device not found"}
async def test_automation_with_unknown_device(hass, caplog, fake_integration):
async def test_automation_with_unknown_device(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, fake_integration
) -> None:
"""Test device automation with a trigger with an unknown device."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -1391,8 +1479,11 @@ async def test_automation_with_unknown_device(hass, caplog, fake_integration):
async def test_automation_with_device_wrong_domain(
hass, caplog, device_registry, fake_integration
):
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
device_registry: dr.DeviceRegistry,
fake_integration,
) -> None:
"""Test device automation where the device doesn't have the right config entry."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})
@ -1428,8 +1519,11 @@ async def test_automation_with_device_wrong_domain(
async def test_automation_with_device_component_not_loaded(
hass, caplog, device_registry, fake_integration
):
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
device_registry: dr.DeviceRegistry,
fake_integration,
) -> None:
"""Test device automation where the device's config entry is not loaded."""
module_cache = hass.data.setdefault(loader.DATA_COMPONENTS, {})