Add type hints to integration tests (part 9) (#87983)

This commit is contained in:
epenet 2023-02-13 12:06:51 +01:00 committed by GitHub
parent 6359775cfc
commit 03710e58b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
63 changed files with 1526 additions and 781 deletions

View file

@ -12,6 +12,7 @@ from homeassistant.components.homekit.const import (
)
from homeassistant.config_entries import SOURCE_IGNORE, SOURCE_IMPORT
from homeassistant.const import CONF_NAME, CONF_PORT, EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_registry import RegistryEntry, RegistryEntryHider
from homeassistant.helpers.entityfilter import CONF_INCLUDE_DOMAINS
from homeassistant.setup import async_setup_component
@ -42,7 +43,7 @@ def _mock_config_entry_with_options_populated():
)
async def test_setup_in_bridge_mode(hass, mock_get_source_ip):
async def test_setup_in_bridge_mode(hass: HomeAssistant, mock_get_source_ip) -> None:
"""Test we can setup a new instance in bridge mode."""
result = await hass.config_entries.flow.async_init(
@ -92,7 +93,9 @@ async def test_setup_in_bridge_mode(hass, mock_get_source_ip):
assert len(mock_setup_entry.mock_calls) == 1
async def test_setup_in_bridge_mode_name_taken(hass, mock_get_source_ip):
async def test_setup_in_bridge_mode_name_taken(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test we can setup a new instance in bridge mode when the name is taken."""
entry = MockConfigEntry(
@ -150,8 +153,8 @@ async def test_setup_in_bridge_mode_name_taken(hass, mock_get_source_ip):
async def test_setup_creates_entries_for_accessory_mode_devices(
hass, mock_get_source_ip
):
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test we can setup a new instance and we create entries for accessory mode devices."""
hass.states.async_set("camera.one", "on")
hass.states.async_set("camera.existing", "on")
@ -240,7 +243,7 @@ async def test_setup_creates_entries_for_accessory_mode_devices(
assert len(mock_setup_entry.mock_calls) == 7
async def test_import(hass, mock_get_source_ip):
async def test_import(hass: HomeAssistant, mock_get_source_ip) -> None:
"""Test we can import instance."""
ignored_entry = MockConfigEntry(domain=DOMAIN, data={}, source=SOURCE_IGNORE)
@ -282,7 +285,9 @@ async def test_import(hass, mock_get_source_ip):
assert len(mock_setup_entry.mock_calls) == 2
async def test_options_flow_exclude_mode_advanced(hass, mock_get_source_ip):
async def test_options_flow_exclude_mode_advanced(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in exclude mode with advanced options."""
config_entry = _mock_config_entry_with_options_populated()
@ -335,7 +340,9 @@ async def test_options_flow_exclude_mode_advanced(hass, mock_get_source_ip):
}
async def test_options_flow_exclude_mode_basic(hass, mock_get_source_ip):
async def test_options_flow_exclude_mode_basic(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in exclude mode."""
config_entry = _mock_config_entry_with_options_populated()
@ -389,13 +396,13 @@ async def test_options_flow_exclude_mode_basic(hass, mock_get_source_ip):
@patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True)
async def test_options_flow_devices(
port_mock,
hass,
hass: HomeAssistant,
demo_cleanup,
device_reg,
entity_reg,
mock_get_source_ip,
mock_async_zeroconf,
):
mock_async_zeroconf: None,
) -> None:
"""Test devices can be bridged."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@ -479,8 +486,8 @@ async def test_options_flow_devices(
@patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True)
async def test_options_flow_devices_preserved_when_advanced_off(
port_mock, hass, mock_get_source_ip, mock_async_zeroconf
):
port_mock, hass: HomeAssistant, mock_get_source_ip, mock_async_zeroconf: None
) -> None:
"""Test devices are preserved if they were added in advanced mode but it was turned off."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@ -551,8 +558,8 @@ async def test_options_flow_devices_preserved_when_advanced_off(
async def test_options_flow_include_mode_with_non_existant_entity(
hass, mock_get_source_ip
):
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in include mode with a non-existent entity."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@ -611,8 +618,8 @@ async def test_options_flow_include_mode_with_non_existant_entity(
async def test_options_flow_exclude_mode_with_non_existant_entity(
hass, mock_get_source_ip
):
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in exclude mode with a non-existent entity."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@ -671,7 +678,9 @@ async def test_options_flow_exclude_mode_with_non_existant_entity(
await hass.config_entries.async_unload(config_entry.entry_id)
async def test_options_flow_include_mode_basic(hass, mock_get_source_ip):
async def test_options_flow_include_mode_basic(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in include mode."""
config_entry = _mock_config_entry_with_options_populated()
@ -717,7 +726,9 @@ async def test_options_flow_include_mode_basic(hass, mock_get_source_ip):
await hass.config_entries.async_unload(config_entry.entry_id)
async def test_options_flow_exclude_mode_with_cameras(hass, mock_get_source_ip):
async def test_options_flow_exclude_mode_with_cameras(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in exclude mode with cameras."""
config_entry = _mock_config_entry_with_options_populated()
@ -824,7 +835,9 @@ async def test_options_flow_exclude_mode_with_cameras(hass, mock_get_source_ip):
await hass.config_entries.async_unload(config_entry.entry_id)
async def test_options_flow_include_mode_with_cameras(hass, mock_get_source_ip):
async def test_options_flow_include_mode_with_cameras(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options in include mode with cameras."""
config_entry = _mock_config_entry_with_options_populated()
@ -958,7 +971,9 @@ async def test_options_flow_include_mode_with_cameras(hass, mock_get_source_ip):
await hass.config_entries.async_unload(config_entry.entry_id)
async def test_options_flow_with_camera_audio(hass, mock_get_source_ip):
async def test_options_flow_with_camera_audio(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options with cameras that support audio."""
config_entry = _mock_config_entry_with_options_populated()
@ -1092,7 +1107,9 @@ async def test_options_flow_with_camera_audio(hass, mock_get_source_ip):
await hass.config_entries.async_unload(config_entry.entry_id)
async def test_options_flow_blocked_when_from_yaml(hass, mock_get_source_ip):
async def test_options_flow_blocked_when_from_yaml(
hass: HomeAssistant, mock_get_source_ip
) -> None:
"""Test config flow options."""
config_entry = MockConfigEntry(
@ -1134,8 +1151,12 @@ async def test_options_flow_blocked_when_from_yaml(hass, mock_get_source_ip):
@patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True)
async def test_options_flow_include_mode_basic_accessory(
port_mock, hass, mock_get_source_ip, hk_driver, mock_async_zeroconf
):
port_mock,
hass: HomeAssistant,
mock_get_source_ip,
hk_driver,
mock_async_zeroconf: None,
) -> None:
"""Test config flow options in include mode with a single accessory."""
config_entry = _mock_config_entry_with_options_populated()
await async_init_entry(hass, config_entry)
@ -1233,7 +1254,9 @@ async def test_options_flow_include_mode_basic_accessory(
await hass.config_entries.async_unload(config_entry.entry_id)
async def test_converting_bridge_to_accessory_mode(hass, hk_driver, mock_get_source_ip):
async def test_converting_bridge_to_accessory_mode(
hass: HomeAssistant, hk_driver, mock_get_source_ip
) -> None:
"""Test we can convert a bridge to accessory mode."""
result = await hass.config_entries.flow.async_init(
@ -1351,8 +1374,13 @@ def _get_schema_default(schema, key_name):
@patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True)
async def test_options_flow_exclude_mode_skips_category_entities(
port_mock, hass, mock_get_source_ip, hk_driver, mock_async_zeroconf, entity_reg
):
port_mock,
hass: HomeAssistant,
mock_get_source_ip,
hk_driver,
mock_async_zeroconf: None,
entity_reg,
) -> None:
"""Ensure exclude mode does not offer category entities."""
config_entry = _mock_config_entry_with_options_populated()
await async_init_entry(hass, config_entry)
@ -1451,8 +1479,13 @@ async def test_options_flow_exclude_mode_skips_category_entities(
@patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True)
async def test_options_flow_exclude_mode_skips_hidden_entities(
port_mock, hass, mock_get_source_ip, hk_driver, mock_async_zeroconf, entity_reg
):
port_mock,
hass: HomeAssistant,
mock_get_source_ip,
hk_driver,
mock_async_zeroconf: None,
entity_reg,
) -> None:
"""Ensure exclude mode does not offer hidden entities."""
config_entry = _mock_config_entry_with_options_populated()
await async_init_entry(hass, config_entry)
@ -1531,8 +1564,13 @@ async def test_options_flow_exclude_mode_skips_hidden_entities(
@patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True)
async def test_options_flow_include_mode_allows_hidden_entities(
port_mock, hass, mock_get_source_ip, hk_driver, mock_async_zeroconf, entity_reg
):
port_mock,
hass: HomeAssistant,
mock_get_source_ip,
hk_driver,
mock_async_zeroconf: None,
entity_reg,
) -> None:
"""Ensure include mode does not offer hidden entities."""
config_entry = _mock_config_entry_with_options_populated()
await async_init_entry(hass, config_entry)