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,6 +1,7 @@
"""Basic checks for HomeKit cameras."""
import base64
from collections.abc import Callable
from aiohomekit.model.services import ServicesTypes
from aiohomekit.testing import FAKE_CAMERA_IMAGE
@ -9,7 +10,7 @@ from homeassistant.components import camera
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_camera(accessory):
@ -18,7 +19,9 @@ def create_camera(accessory):
async def test_migrate_unique_ids(
hass: HomeAssistant, entity_registry: er.EntityRegistry
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
get_next_aid: Callable[[], int],
) -> None:
"""Test migrating entity unique ids."""
aid = get_next_aid()
@ -27,23 +30,23 @@ async def test_migrate_unique_ids(
"homekit_controller",
f"homekit-0001-aid:{aid}",
)
await setup_test_component(hass, create_camera)
await setup_test_component(hass, aid, create_camera)
assert (
entity_registry.async_get(camera.entity_id).unique_id
== f"00:00:00:00:00:00_{aid}"
)
async def test_read_state(hass: HomeAssistant) -> None:
async def test_read_state(hass: HomeAssistant, get_next_aid: Callable[[], int]) -> None:
"""Test reading the state of a HomeKit camera."""
helper = await setup_test_component(hass, create_camera)
helper = await setup_test_component(hass, get_next_aid(), create_camera)
state = await helper.poll_and_get_state()
assert state.state == "idle"
async def test_get_image(hass: HomeAssistant) -> None:
async def test_get_image(hass: HomeAssistant, get_next_aid: Callable[[], int]) -> None:
"""Test getting a JPEG from a camera."""
helper = await setup_test_component(hass, create_camera)
helper = await setup_test_component(hass, get_next_aid(), create_camera)
image = await camera.async_get_image(hass, helper.entity_id)
assert image.content == base64.b64decode(FAKE_CAMERA_IMAGE)