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 HomeKit sensor."""
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 Helper, get_next_aid, setup_test_component
from .common import Helper, setup_test_component
def create_switch_with_spray_level(accessory):
@ -31,7 +33,9 @@ def create_switch_with_spray_level(accessory):
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 number unique id."""
aid = get_next_aid()
@ -41,7 +45,7 @@ async def test_migrate_unique_id(
f"homekit-0001-aid:{aid}-sid:8-cid:9",
suggested_object_id="testdevice_spray_quantity",
)
await setup_test_component(hass, create_switch_with_spray_level)
await setup_test_component(hass, aid, create_switch_with_spray_level)
assert (
entity_registry.async_get(number.entity_id).unique_id
@ -49,9 +53,13 @@ async def test_migrate_unique_id(
)
async def test_read_number(hass: HomeAssistant) -> None:
async def test_read_number(
hass: HomeAssistant, get_next_aid: Callable[[], int]
) -> None:
"""Test a switch service that has a sensor characteristic is correctly handled."""
helper = await setup_test_component(hass, create_switch_with_spray_level)
helper = await setup_test_component(
hass, get_next_aid(), create_switch_with_spray_level
)
# Helper will be for the primary entity, which is the outlet. Make a helper for the sensor.
spray_level = Helper(
@ -75,9 +83,13 @@ async def test_read_number(hass: HomeAssistant) -> None:
assert state.state == "5"
async def test_write_number(hass: HomeAssistant) -> None:
async def test_write_number(
hass: HomeAssistant, get_next_aid: Callable[[], int]
) -> None:
"""Test a switch service that has a sensor characteristic is correctly handled."""
helper = await setup_test_component(hass, create_switch_with_spray_level)
helper = await setup_test_component(
hass, get_next_aid(), create_switch_with_spray_level
)
# Helper will be for the primary entity, which is the outlet. Make a helper for the sensor.
spray_level = Helper(