Fix homekit_controller tests to avoid global aid generation (#119852)

This commit is contained in:
J. Nick Koston 2024-07-17 19:10:02 -05:00 committed by GitHub
parent 454ca0ce95
commit e2276458ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 792 additions and 344 deletions

View file

@ -1,12 +1,14 @@
"""Basic checks for HomeKitLock."""
from collections.abc import Callable
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry as er
from .common import get_next_aid, setup_test_component
from .common import setup_test_component
def create_lock_service(accessory):
@ -29,9 +31,11 @@ def create_lock_service(accessory):
return service
async def test_switch_change_lock_state(hass: HomeAssistant) -> None:
async def test_switch_change_lock_state(
hass: HomeAssistant, get_next_aid: Callable[[], int]
) -> None:
"""Test that we can turn a HomeKit lock on and off again."""
helper = await setup_test_component(hass, create_lock_service)
helper = await setup_test_component(hass, get_next_aid(), create_lock_service)
await hass.services.async_call(
"lock", "lock", {"entity_id": "lock.testdevice"}, blocking=True
@ -54,9 +58,11 @@ async def test_switch_change_lock_state(hass: HomeAssistant) -> None:
)
async def test_switch_read_lock_state(hass: HomeAssistant) -> None:
async def test_switch_read_lock_state(
hass: HomeAssistant, get_next_aid: Callable[[], int]
) -> None:
"""Test that we can read the state of a HomeKit lock accessory."""
helper = await setup_test_component(hass, create_lock_service)
helper = await setup_test_component(hass, get_next_aid(), create_lock_service)
state = await helper.async_update(
ServicesTypes.LOCK_MECHANISM,
@ -119,7 +125,9 @@ async def test_switch_read_lock_state(hass: HomeAssistant) -> None:
async def test_migrate_unique_id(
hass: HomeAssistant, entity_registry: er.EntityRegistry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
get_next_aid: Callable[[], int],
) -> None:
"""Test a we can migrate a lock unique id."""
aid = get_next_aid()
@ -128,7 +136,7 @@ async def test_migrate_unique_id(
"homekit_controller",
f"homekit-00:00:00:00:00:00-{aid}-8",
)
await setup_test_component(hass, create_lock_service)
await setup_test_component(hass, aid, create_lock_service)
assert (
entity_registry.async_get(lock_entry.entity_id).unique_id