mirror of
https://github.com/home-assistant/core.git
synced 2025-11-10 19:40:11 +00:00
Migrate HomeKit Controller to use stable identifiers (#80064)
This commit is contained in:
@@ -9,7 +9,12 @@ import os
|
||||
from typing import Any, Final
|
||||
from unittest import mock
|
||||
|
||||
from aiohomekit.model import Accessories, AccessoriesState, Accessory
|
||||
from aiohomekit.model import (
|
||||
Accessories,
|
||||
AccessoriesState,
|
||||
Accessory,
|
||||
mixin as model_mixin,
|
||||
)
|
||||
from aiohomekit.testing import FakeController, FakePairing
|
||||
from aiohomekit.zeroconf import HomeKitService
|
||||
|
||||
@@ -19,7 +24,6 @@ from homeassistant.components.homekit_controller.const import (
|
||||
DOMAIN,
|
||||
HOMEKIT_ACCESSORY_DISPATCH,
|
||||
IDENTIFIER_ACCESSORY_ID,
|
||||
IDENTIFIER_SERIAL_NUMBER,
|
||||
)
|
||||
from homeassistant.components.homekit_controller.utils import async_get_controller
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@@ -320,7 +324,6 @@ async def assert_devices_and_entities_created(
|
||||
|
||||
device = device_registry.async_get_device(
|
||||
{
|
||||
(IDENTIFIER_SERIAL_NUMBER, expected.serial_number),
|
||||
(IDENTIFIER_ACCESSORY_ID, expected.unique_id),
|
||||
}
|
||||
)
|
||||
@@ -336,21 +339,15 @@ async def assert_devices_and_entities_created(
|
||||
|
||||
# We might have matched the device by one identifier only
|
||||
# Lets check that the other one is correct. Otherwise the test might silently be wrong.
|
||||
serial_number_set = False
|
||||
accessory_id_set = False
|
||||
|
||||
for key, value in device.identifiers:
|
||||
if key == IDENTIFIER_SERIAL_NUMBER:
|
||||
assert value == expected.serial_number
|
||||
serial_number_set = True
|
||||
|
||||
elif key == IDENTIFIER_ACCESSORY_ID:
|
||||
if key == IDENTIFIER_ACCESSORY_ID:
|
||||
assert value == expected.unique_id
|
||||
accessory_id_set = True
|
||||
|
||||
# If unique_id or serial is provided it MUST actually appear in the device registry entry.
|
||||
assert (not expected.unique_id) ^ accessory_id_set
|
||||
assert (not expected.serial_number) ^ serial_number_set
|
||||
|
||||
for entity_info in expected.entities:
|
||||
entity = entity_registry.async_get(entity_info.entity_id)
|
||||
@@ -410,3 +407,8 @@ async def remove_device(ws_client, device_id, config_entry_id):
|
||||
)
|
||||
response = await ws_client.receive_json()
|
||||
return response["success"]
|
||||
|
||||
|
||||
def get_next_aid():
|
||||
"""Get next aid."""
|
||||
return model_mixin.id_counter + 1
|
||||
|
||||
Reference in New Issue
Block a user