mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
fix tests
This commit is contained in:
parent
6e85f90447
commit
31764247f3
@ -24,6 +24,7 @@ from homeassistant.components.device_tracker import (
|
|||||||
SourceType,
|
SourceType,
|
||||||
)
|
)
|
||||||
from homeassistant.components.dhcp.const import DOMAIN
|
from homeassistant.components.dhcp.const import DOMAIN
|
||||||
|
from homeassistant.components.dhcp.models import DHCPData
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_STARTED,
|
EVENT_HOMEASSISTANT_STARTED,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
@ -151,8 +152,7 @@ async def _async_get_handle_dhcp_packet(
|
|||||||
address_data = {}
|
address_data = {}
|
||||||
dhcp_watcher = dhcp.DHCPWatcher(
|
dhcp_watcher = dhcp.DHCPWatcher(
|
||||||
hass,
|
hass,
|
||||||
address_data,
|
DHCPData(integration_matchers, set(), address_data),
|
||||||
integration_matchers,
|
|
||||||
)
|
)
|
||||||
with patch("aiodhcpwatcher.async_start"):
|
with patch("aiodhcpwatcher.async_start"):
|
||||||
await dhcp_watcher.async_start()
|
await dhcp_watcher.async_start()
|
||||||
@ -666,6 +666,32 @@ async def test_setup_fails_with_broken_libpcap(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _make_device_tracker_watcher(
|
||||||
|
hass: HomeAssistant, matchers: list[dhcp.DHCPMatcher]
|
||||||
|
) -> dhcp.DeviceTrackerWatcher:
|
||||||
|
return dhcp.DeviceTrackerWatcher(
|
||||||
|
hass,
|
||||||
|
DHCPData(
|
||||||
|
dhcp.async_index_integration_matchers(matchers),
|
||||||
|
set(),
|
||||||
|
{},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _make_network_watcher(
|
||||||
|
hass: HomeAssistant, matchers: list[dhcp.DHCPMatcher]
|
||||||
|
) -> dhcp.NetworkWatcher:
|
||||||
|
return dhcp.NetworkWatcher(
|
||||||
|
hass,
|
||||||
|
DHCPData(
|
||||||
|
dhcp.async_index_integration_matchers(matchers),
|
||||||
|
set(),
|
||||||
|
{},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def test_device_tracker_hostname_and_macaddress_exists_before_start(
|
async def test_device_tracker_hostname_and_macaddress_exists_before_start(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -682,18 +708,15 @@ async def test_device_tracker_hostname_and_macaddress_exists_before_start(
|
|||||||
)
|
)
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -716,18 +739,15 @@ async def test_device_tracker_hostname_and_macaddress_exists_before_start(
|
|||||||
async def test_device_tracker_registered(hass: HomeAssistant) -> None:
|
async def test_device_tracker_registered(hass: HomeAssistant) -> None:
|
||||||
"""Test matching based on hostname and macaddress when registered."""
|
"""Test matching based on hostname and macaddress when registered."""
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerRegisteredWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -756,18 +776,15 @@ async def test_device_tracker_registered(hass: HomeAssistant) -> None:
|
|||||||
async def test_device_tracker_registered_hostname_none(hass: HomeAssistant) -> None:
|
async def test_device_tracker_registered_hostname_none(hass: HomeAssistant) -> None:
|
||||||
"""Test handle None hostname."""
|
"""Test handle None hostname."""
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerRegisteredWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -789,18 +806,15 @@ async def test_device_tracker_hostname_and_macaddress_after_start(
|
|||||||
"""Test matching based on hostname and macaddress after start."""
|
"""Test matching based on hostname and macaddress after start."""
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -837,18 +851,15 @@ async def test_device_tracker_hostname_and_macaddress_after_start_not_home(
|
|||||||
"""Test matching based on hostname and macaddress after start but not home."""
|
"""Test matching based on hostname and macaddress after start but not home."""
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -875,9 +886,8 @@ async def test_device_tracker_hostname_and_macaddress_after_start_not_router(
|
|||||||
"""Test matching based on hostname and macaddress after start but not router."""
|
"""Test matching based on hostname and macaddress after start but not router."""
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
@ -905,9 +915,8 @@ async def test_device_tracker_hostname_and_macaddress_after_start_hostname_missi
|
|||||||
"""Test matching based on hostname and macaddress after start but missing hostname."""
|
"""Test matching based on hostname and macaddress after start but missing hostname."""
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
@ -934,9 +943,8 @@ async def test_device_tracker_invalid_ip_address(
|
|||||||
"""Test an invalid ip address."""
|
"""Test an invalid ip address."""
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
[{"domain": "mock-domain", "hostname": "connect", "macaddress": "B8B7F1*"}],
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
@ -974,18 +982,15 @@ async def test_device_tracker_ignore_self_assigned_ips_before_start(
|
|||||||
)
|
)
|
||||||
|
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
device_tracker_watcher = dhcp.DeviceTrackerWatcher(
|
device_tracker_watcher = _make_device_tracker_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -1010,18 +1015,15 @@ async def test_aiodiscover_finds_new_hosts(hass: HomeAssistant) -> None:
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
device_tracker_watcher = dhcp.NetworkWatcher(
|
device_tracker_watcher = _make_network_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -1073,18 +1075,15 @@ async def test_aiodiscover_does_not_call_again_on_shorter_hostname(
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
device_tracker_watcher = dhcp.NetworkWatcher(
|
device_tracker_watcher = _make_network_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "irobot-*",
|
"hostname": "irobot-*",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -1123,19 +1122,17 @@ async def test_aiodiscover_finds_new_hosts_after_interval(hass: HomeAssistant) -
|
|||||||
return_value=[],
|
return_value=[],
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
device_tracker_watcher = dhcp.NetworkWatcher(
|
device_tracker_watcher = _make_network_watcher(
|
||||||
hass,
|
hass,
|
||||||
{},
|
|
||||||
dhcp.async_index_integration_matchers(
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"domain": "mock-domain",
|
"domain": "mock-domain",
|
||||||
"hostname": "connect",
|
"hostname": "connect",
|
||||||
"macaddress": "B8B7F1*",
|
"macaddress": "B8B7F1*",
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
device_tracker_watcher.async_start()
|
device_tracker_watcher.async_start()
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -1235,7 +1232,7 @@ async def test_dhcp_rediscover(
|
|||||||
hass, integration_matchers, address_data
|
hass, integration_matchers, address_data
|
||||||
)
|
)
|
||||||
rediscovery_watcher = dhcp.RediscoveryWatcher(
|
rediscovery_watcher = dhcp.RediscoveryWatcher(
|
||||||
hass, address_data, integration_matchers
|
hass, DHCPData(integration_matchers, set(), address_data)
|
||||||
)
|
)
|
||||||
rediscovery_watcher.async_start()
|
rediscovery_watcher.async_start()
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
@ -1329,7 +1326,7 @@ async def test_dhcp_rediscover_no_match(
|
|||||||
hass, integration_matchers, address_data
|
hass, integration_matchers, address_data
|
||||||
)
|
)
|
||||||
rediscovery_watcher = dhcp.RediscoveryWatcher(
|
rediscovery_watcher = dhcp.RediscoveryWatcher(
|
||||||
hass, address_data, integration_matchers
|
hass, DHCPData(integration_matchers, set(), address_data)
|
||||||
)
|
)
|
||||||
rediscovery_watcher.async_start()
|
rediscovery_watcher.async_start()
|
||||||
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
with patch.object(hass.config_entries.flow, "async_init") as mock_init:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user