Prepare for new aiohomekit lifecycle API (#66340)
This commit is contained in:
parent
2f220b27d4
commit
0daf20c0cc
11 changed files with 79 additions and 28 deletions
|
@ -174,7 +174,9 @@ async def setup_platform(hass):
|
|||
"""Load the platform but with a fake Controller API."""
|
||||
config = {"discovery": {}}
|
||||
|
||||
with mock.patch("aiohomekit.Controller") as controller:
|
||||
with mock.patch(
|
||||
"homeassistant.components.homekit_controller.utils.Controller"
|
||||
) as controller:
|
||||
fake_controller = controller.return_value = FakeController()
|
||||
await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
|
|
|
@ -27,7 +27,10 @@ def utcnow(request):
|
|||
def controller(hass):
|
||||
"""Replace aiohomekit.Controller with an instance of aiohomekit.testing.FakeController."""
|
||||
instance = FakeController()
|
||||
with unittest.mock.patch("aiohomekit.Controller", return_value=instance):
|
||||
with unittest.mock.patch(
|
||||
"homeassistant.components.homekit_controller.utils.Controller",
|
||||
return_value=instance,
|
||||
):
|
||||
yield instance
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ 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
|
||||
|
@ -35,19 +34,16 @@ async def test_unload_on_stop(hass, utcnow):
|
|||
async def test_async_remove_entry(hass: HomeAssistant):
|
||||
"""Test unpairing a component."""
|
||||
helper = await setup_test_component(hass, create_motion_sensor_service)
|
||||
controller = helper.pairing.controller
|
||||
|
||||
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 len(controller.pairings) == 1
|
||||
|
||||
assert hkid in hass.data[ENTITY_MAP].storage_data
|
||||
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
|
||||
# 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
|
||||
assert hkid not in hass.data[ENTITY_MAP].storage_data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue