Support unpairing homekit accessories from homekit_controller (#65065)
This commit is contained in:
parent
e92078cf50
commit
f49cfe866a
3 changed files with 44 additions and 25 deletions
|
@ -4,8 +4,11 @@ from unittest.mock import patch
|
|||
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
from aiohomekit.testing import FakeController
|
||||
|
||||
from homeassistant.components.homekit_controller.const import ENTITY_MAP
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.components.homekit_controller.common import setup_test_component
|
||||
|
||||
|
@ -27,3 +30,24 @@ async def test_unload_on_stop(hass, utcnow):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert async_unlock_mock.called
|
||||
|
||||
|
||||
async def test_async_remove_entry(hass: HomeAssistant):
|
||||
"""Test unpairing a component."""
|
||||
helper = await setup_test_component(hass, create_motion_sensor_service)
|
||||
|
||||
hkid = "00:00:00:00:00:00"
|
||||
|
||||
with patch("aiohomekit.Controller") as controller_cls:
|
||||
# Setup a fake controller with 1 pairing
|
||||
controller = controller_cls.return_value = FakeController()
|
||||
await controller.add_paired_device([helper.accessory], hkid)
|
||||
assert len(controller.pairings) == 1
|
||||
|
||||
assert hkid in hass.data[ENTITY_MAP].storage_data
|
||||
|
||||
# Remove it via config entry and number of pairings should go down
|
||||
await helper.config_entry.async_remove(hass)
|
||||
assert len(controller.pairings) == 0
|
||||
|
||||
assert hkid not in hass.data[ENTITY_MAP].storage_data
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.homekit_controller import async_remove_entry
|
||||
from homeassistant.components.homekit_controller.const import ENTITY_MAP
|
||||
|
||||
from tests.common import flush_store
|
||||
|
@ -79,26 +77,3 @@ async def test_storage_is_updated_on_add(hass, hass_storage, utcnow):
|
|||
# Is saved out to store?
|
||||
await flush_store(entity_map.store)
|
||||
assert hkid in hass_storage[ENTITY_MAP]["data"]["pairings"]
|
||||
|
||||
|
||||
async def test_storage_is_removed_on_config_entry_removal(hass, utcnow):
|
||||
"""Test entity map storage is cleaned up on config entry removal."""
|
||||
await setup_test_component(hass, create_lightbulb_service)
|
||||
|
||||
hkid = "00:00:00:00:00:00"
|
||||
|
||||
pairing_data = {"AccessoryPairingID": hkid}
|
||||
|
||||
entry = config_entries.ConfigEntry(
|
||||
1,
|
||||
"homekit_controller",
|
||||
"TestData",
|
||||
pairing_data,
|
||||
"test",
|
||||
)
|
||||
|
||||
assert hkid in hass.data[ENTITY_MAP].storage_data
|
||||
|
||||
await async_remove_entry(hass, entry)
|
||||
|
||||
assert hkid not in hass.data[ENTITY_MAP].storage_data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue