mirror of
https://github.com/home-assistant/core.git
synced 2025-11-16 06:20:07 +00:00
Fix homekit_controller tests to avoid global aid generation (#119852)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""Tests for homekit_controller init."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
import pathlib
|
||||
from unittest.mock import patch
|
||||
@@ -46,9 +47,11 @@ def create_motion_sensor_service(accessory):
|
||||
cur_state.value = 0
|
||||
|
||||
|
||||
async def test_unload_on_stop(hass: HomeAssistant) -> None:
|
||||
async def test_unload_on_stop(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test async_unload is called on stop."""
|
||||
await setup_test_component(hass, create_motion_sensor_service)
|
||||
await setup_test_component(hass, get_next_aid(), create_motion_sensor_service)
|
||||
with patch(
|
||||
"homeassistant.components.homekit_controller.HKDevice.async_unload"
|
||||
) as async_unlock_mock:
|
||||
@@ -58,9 +61,13 @@ async def test_unload_on_stop(hass: HomeAssistant) -> None:
|
||||
assert async_unlock_mock.called
|
||||
|
||||
|
||||
async def test_async_remove_entry(hass: HomeAssistant) -> None:
|
||||
async def test_async_remove_entry(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test unpairing a component."""
|
||||
helper = await setup_test_component(hass, create_motion_sensor_service)
|
||||
helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_motion_sensor_service
|
||||
)
|
||||
controller = helper.pairing.controller
|
||||
|
||||
hkid = "00:00:00:00:00:00"
|
||||
@@ -88,10 +95,13 @@ async def test_device_remove_devices(
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
get_next_aid: Callable[[], int],
|
||||
) -> None:
|
||||
"""Test we can only remove a device that no longer exists."""
|
||||
assert await async_setup_component(hass, "config", {})
|
||||
helper: Helper = await setup_test_component(hass, create_alive_service)
|
||||
helper: Helper = await setup_test_component(
|
||||
hass, get_next_aid(), create_alive_service
|
||||
)
|
||||
config_entry = helper.config_entry
|
||||
entry_id = config_entry.entry_id
|
||||
|
||||
@@ -110,10 +120,13 @@ async def test_device_remove_devices(
|
||||
assert response["success"]
|
||||
|
||||
|
||||
async def test_offline_device_raises(hass: HomeAssistant, controller) -> None:
|
||||
async def test_offline_device_raises(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int], controller
|
||||
) -> None:
|
||||
"""Test an offline device raises ConfigEntryNotReady."""
|
||||
|
||||
is_connected = False
|
||||
aid = get_next_aid()
|
||||
|
||||
class OfflineFakePairing(FakePairing):
|
||||
"""Fake pairing that can flip is_connected."""
|
||||
@@ -140,7 +153,7 @@ async def test_offline_device_raises(hass: HomeAssistant, controller) -> None:
|
||||
return {}
|
||||
|
||||
accessory = Accessory.create_with_info(
|
||||
"TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
aid, "TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
)
|
||||
create_alive_service(accessory)
|
||||
|
||||
@@ -162,11 +175,12 @@ async def test_offline_device_raises(hass: HomeAssistant, controller) -> None:
|
||||
|
||||
|
||||
async def test_ble_device_only_checks_is_available(
|
||||
hass: HomeAssistant, controller
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int], controller
|
||||
) -> None:
|
||||
"""Test a BLE device only checks is_available."""
|
||||
|
||||
is_available = False
|
||||
aid = get_next_aid()
|
||||
|
||||
class FakeBLEPairing(FakePairing):
|
||||
"""Fake BLE pairing that can flip is_available."""
|
||||
@@ -197,7 +211,7 @@ async def test_ble_device_only_checks_is_available(
|
||||
return {}
|
||||
|
||||
accessory = Accessory.create_with_info(
|
||||
"TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
aid, "TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
)
|
||||
create_alive_service(accessory)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user