1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

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
50 changed files with 563 additions and 332 deletions

View File

@@ -95,7 +95,9 @@ async def test_reading_broken_yaml_config(hass: HomeAssistant) -> None:
assert res[0].dev_id == "my_device"
async def test_reading_yaml_config(hass, yaml_devices, enable_custom_integrations):
async def test_reading_yaml_config(
hass: HomeAssistant, yaml_devices, enable_custom_integrations: None
) -> None:
"""Test the rendering of the YAML configuration."""
dev_id = "test"
device = legacy.Device(
@@ -125,7 +127,7 @@ async def test_reading_yaml_config(hass, yaml_devices, enable_custom_integration
@patch("homeassistant.components.device_tracker.const.LOGGER.warning")
async def test_duplicate_mac_dev_id(mock_warning, hass):
async def test_duplicate_mac_dev_id(mock_warning, hass: HomeAssistant) -> None:
"""Test adding duplicate MACs or device IDs to DeviceTracker."""
devices = [
legacy.Device(
@@ -162,7 +164,9 @@ async def test_duplicate_mac_dev_id(mock_warning, hass):
assert "Duplicate device IDs" in args[0], "Duplicate device IDs warning expected"
async def test_setup_without_yaml_file(hass, yaml_devices, enable_custom_integrations):
async def test_setup_without_yaml_file(
hass: HomeAssistant, yaml_devices, enable_custom_integrations: None
) -> None:
"""Test with no YAML file."""
with assert_setup_component(1, device_tracker.DOMAIN):
assert await async_setup_component(hass, device_tracker.DOMAIN, TEST_PLATFORM)
@@ -210,7 +214,9 @@ async def test_gravatar_and_picture(hass: HomeAssistant) -> None:
@patch("homeassistant.components.device_tracker.legacy.DeviceTracker.see")
@patch("homeassistant.components.demo.device_tracker.setup_scanner", autospec=True)
async def test_discover_platform(mock_demo_setup_scanner, mock_see, hass):
async def test_discover_platform(
mock_demo_setup_scanner, mock_see, hass: HomeAssistant
) -> None:
"""Test discovery of device_tracker demo platform."""
with patch("homeassistant.components.device_tracker.legacy.update_config"):
await discovery.async_load_platform(
@@ -227,7 +233,11 @@ async def test_discover_platform(mock_demo_setup_scanner, mock_see, hass):
)
async def test_update_stale(hass, mock_device_tracker_conf, enable_custom_integrations):
async def test_update_stale(
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test stalled update."""
scanner = getattr(hass.components, "test.device_tracker").SCANNER
@@ -269,8 +279,10 @@ async def test_update_stale(hass, mock_device_tracker_conf, enable_custom_integr
async def test_entity_attributes(
hass, mock_device_tracker_conf, enable_custom_integrations
):
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test the entity attributes."""
devices = mock_device_tracker_conf
dev_id = "test_entity"
@@ -302,7 +314,9 @@ async def test_entity_attributes(
@patch("homeassistant.components.device_tracker.legacy.DeviceTracker.async_see")
async def test_see_service(mock_see, hass, enable_custom_integrations):
async def test_see_service(
mock_see, hass: HomeAssistant, enable_custom_integrations: None
) -> None:
"""Test the see service with a unicode dev_id and NO MAC."""
with assert_setup_component(1, device_tracker.DOMAIN):
assert await async_setup_component(hass, device_tracker.DOMAIN, TEST_PLATFORM)
@@ -330,8 +344,10 @@ async def test_see_service(mock_see, hass, enable_custom_integrations):
async def test_see_service_guard_config_entry(
hass, mock_device_tracker_conf, enable_custom_integrations
):
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test the guard if the device is registered in the entity registry."""
mock_entry = Mock()
dev_id = "test"
@@ -348,8 +364,10 @@ async def test_see_service_guard_config_entry(
async def test_new_device_event_fired(
hass, mock_device_tracker_conf, enable_custom_integrations
):
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test that the device tracker will fire an event."""
with assert_setup_component(1, device_tracker.DOMAIN):
assert await async_setup_component(hass, device_tracker.DOMAIN, TEST_PLATFORM)
@@ -380,8 +398,10 @@ async def test_new_device_event_fired(
async def test_duplicate_yaml_keys(
hass, mock_device_tracker_conf, enable_custom_integrations
):
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test that the device tracker will not generate invalid YAML."""
devices = mock_device_tracker_conf
with assert_setup_component(1, device_tracker.DOMAIN):
@@ -397,8 +417,10 @@ async def test_duplicate_yaml_keys(
async def test_invalid_dev_id(
hass, mock_device_tracker_conf, enable_custom_integrations
):
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test that the device tracker will not allow invalid dev ids."""
devices = mock_device_tracker_conf
with assert_setup_component(1, device_tracker.DOMAIN):
@@ -410,7 +432,9 @@ async def test_invalid_dev_id(
assert not devices
async def test_see_state(hass, yaml_devices, enable_custom_integrations):
async def test_see_state(
hass: HomeAssistant, yaml_devices, enable_custom_integrations: None
) -> None:
"""Test device tracker see records state correctly."""
assert await async_setup_component(hass, device_tracker.DOMAIN, TEST_PLATFORM)
@@ -447,8 +471,10 @@ async def test_see_state(hass, yaml_devices, enable_custom_integrations):
async def test_see_passive_zone_state(
hass, mock_device_tracker_conf, enable_custom_integrations
):
hass: HomeAssistant,
mock_device_tracker_conf: list[legacy.Device],
enable_custom_integrations: None,
) -> None:
"""Test that the device tracker sets gps for passive trackers."""
now = dt_util.utcnow()
@@ -519,7 +545,9 @@ async def test_see_passive_zone_state(
@patch("homeassistant.components.device_tracker.const.LOGGER.warning")
async def test_see_failures(mock_warning, hass, mock_device_tracker_conf):
async def test_see_failures(
mock_warning, hass: HomeAssistant, mock_device_tracker_conf: list[legacy.Device]
) -> None:
"""Test that the device tracker see failures."""
devices = mock_device_tracker_conf
tracker = legacy.DeviceTracker(hass, timedelta(seconds=60), 0, {}, [])
@@ -578,8 +606,10 @@ async def test_bad_platform(hass: HomeAssistant) -> None:
async def test_adding_unknown_device_to_config(
mock_device_tracker_conf, hass, enable_custom_integrations
):
mock_device_tracker_conf: list[legacy.Device],
hass: HomeAssistant,
enable_custom_integrations: None,
) -> None:
"""Test the adding of unknown devices to configuration file."""
scanner = getattr(hass.components, "test.device_tracker").SCANNER
scanner.reset()
@@ -597,7 +627,9 @@ async def test_adding_unknown_device_to_config(
assert device.track
async def test_picture_and_icon_on_see_discovery(mock_device_tracker_conf, hass):
async def test_picture_and_icon_on_see_discovery(
mock_device_tracker_conf: list[legacy.Device], hass: HomeAssistant
) -> None:
"""Test that picture and icon are set in initial see."""
tracker = legacy.DeviceTracker(hass, timedelta(seconds=60), False, {}, [])
await tracker.async_see(dev_id=11, picture="pic_url", icon="mdi:icon")
@@ -607,7 +639,9 @@ async def test_picture_and_icon_on_see_discovery(mock_device_tracker_conf, hass)
assert mock_device_tracker_conf[0].entity_picture == "pic_url"
async def test_backward_compatibility_for_track_new(mock_device_tracker_conf, hass):
async def test_backward_compatibility_for_track_new(
mock_device_tracker_conf: list[legacy.Device], hass: HomeAssistant
) -> None:
"""Test backward compatibility for track new."""
tracker = legacy.DeviceTracker(
hass, timedelta(seconds=60), False, {device_tracker.CONF_TRACK_NEW: True}, []
@@ -618,7 +652,9 @@ async def test_backward_compatibility_for_track_new(mock_device_tracker_conf, ha
assert mock_device_tracker_conf[0].track is False
async def test_old_style_track_new_is_skipped(mock_device_tracker_conf, hass):
async def test_old_style_track_new_is_skipped(
mock_device_tracker_conf: list[legacy.Device], hass: HomeAssistant
) -> None:
"""Test old style config is skipped."""
tracker = legacy.DeviceTracker(
hass, timedelta(seconds=60), None, {device_tracker.CONF_TRACK_NEW: False}, []