Restore accessory state into pairing using new HKC methods (#75276)
This commit is contained in:
parent
ecc219fbc1
commit
b9c8d65940
14 changed files with 130 additions and 91 deletions
|
@ -9,7 +9,7 @@ import os
|
|||
from typing import Any, Final
|
||||
from unittest import mock
|
||||
|
||||
from aiohomekit.model import Accessories, Accessory
|
||||
from aiohomekit.model import Accessories, AccessoriesState, Accessory
|
||||
from aiohomekit.testing import FakeController, FakePairing
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
|
@ -225,7 +225,9 @@ async def device_config_changed(hass, accessories):
|
|||
accessories_obj = Accessories()
|
||||
for accessory in accessories:
|
||||
accessories_obj.add_accessory(accessory)
|
||||
pairing.accessories = accessories_obj
|
||||
pairing._accessories_state = AccessoriesState(
|
||||
accessories_obj, pairing.config_num + 1
|
||||
)
|
||||
|
||||
discovery_info = zeroconf.ZeroconfServiceInfo(
|
||||
host="127.0.0.1",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import asyncio
|
||||
from unittest import mock
|
||||
import unittest.mock
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import aiohomekit
|
||||
from aiohomekit.exceptions import AuthenticationError
|
||||
|
@ -492,7 +492,7 @@ async def test_discovery_already_configured_update_csharp(hass, controller):
|
|||
|
||||
connection_mock = AsyncMock()
|
||||
connection_mock.pairing.connect.reconnect_soon = AsyncMock()
|
||||
connection_mock.async_refresh_entity_map = AsyncMock()
|
||||
connection_mock.async_notify_config_changed = MagicMock()
|
||||
hass.data[KNOWN_DEVICES] = {"AA:BB:CC:DD:EE:FF": connection_mock}
|
||||
|
||||
device = setup_mock_accessory(controller)
|
||||
|
@ -515,7 +515,7 @@ async def test_discovery_already_configured_update_csharp(hass, controller):
|
|||
|
||||
assert entry.data["AccessoryIP"] == discovery_info.host
|
||||
assert entry.data["AccessoryPort"] == discovery_info.port
|
||||
assert connection_mock.async_refresh_entity_map_and_entities.await_count == 1
|
||||
assert connection_mock.async_notify_config_changed.call_count == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exception,expected", PAIRING_START_ABORT_ERRORS)
|
||||
|
|
|
@ -28,6 +28,7 @@ async def test_config_entry(hass: HomeAssistant, hass_client: ClientSession, utc
|
|||
"version": 1,
|
||||
"data": {"AccessoryPairingID": "00:00:00:00:00:00"},
|
||||
},
|
||||
"config-num": 0,
|
||||
"entity-map": [
|
||||
{
|
||||
"aid": 1,
|
||||
|
@ -299,6 +300,7 @@ async def test_device(hass: HomeAssistant, hass_client: ClientSession, utcnow):
|
|||
"version": 1,
|
||||
"data": {"AccessoryPairingID": "00:00:00:00:00:00"},
|
||||
},
|
||||
"config-num": 0,
|
||||
"entity-map": [
|
||||
{
|
||||
"aid": 1,
|
||||
|
|
|
@ -111,8 +111,16 @@ async def test_offline_device_raises(hass, controller):
|
|||
nonlocal is_connected
|
||||
return is_connected
|
||||
|
||||
def get_characteristics(self, chars, *args, **kwargs):
|
||||
raise AccessoryDisconnectedError("any")
|
||||
async def async_populate_accessories_state(self, *args, **kwargs):
|
||||
nonlocal is_connected
|
||||
if not is_connected:
|
||||
raise AccessoryDisconnectedError("any")
|
||||
|
||||
async def get_characteristics(self, chars, *args, **kwargs):
|
||||
nonlocal is_connected
|
||||
if not is_connected:
|
||||
raise AccessoryDisconnectedError("any")
|
||||
return {}
|
||||
|
||||
with patch("aiohomekit.testing.FakePairing", OfflineFakePairing):
|
||||
await async_setup_component(hass, DOMAIN, {})
|
||||
|
|
|
@ -3,6 +3,7 @@ from aiohomekit.model.characteristics import CharacteristicsTypes
|
|||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant.components.homekit_controller.const import ENTITY_MAP
|
||||
from homeassistant.components.homekit_controller.storage import EntityMapStorage
|
||||
|
||||
from tests.common import flush_store
|
||||
from tests.components.homekit_controller.common import (
|
||||
|
@ -68,7 +69,7 @@ async def test_storage_is_updated_on_add(hass, hass_storage, utcnow):
|
|||
"""Test entity map storage is cleaned up on adding an accessory."""
|
||||
await setup_test_component(hass, create_lightbulb_service)
|
||||
|
||||
entity_map = hass.data[ENTITY_MAP]
|
||||
entity_map: EntityMapStorage = hass.data[ENTITY_MAP]
|
||||
hkid = "00:00:00:00:00:00"
|
||||
|
||||
# Is in memory store updated?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue