mirror of
https://github.com/home-assistant/core.git
synced 2025-11-16 06:20:07 +00:00
Fix listener leak in HomeKit on reload (#56143)
* Fix listener leak in HomeKit on reload * Fix mocking
This commit is contained in:
@@ -442,11 +442,12 @@ async def test_homekit_remove_accessory(hass, mock_zeroconf):
|
||||
homekit.driver = "driver"
|
||||
homekit.bridge = _mock_pyhap_bridge()
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.stop = AsyncMock()
|
||||
homekit.bridge.accessories = {6: acc_mock}
|
||||
|
||||
acc = homekit.remove_bridge_accessory(6)
|
||||
acc = await homekit.async_remove_bridge_accessory(6)
|
||||
assert acc is acc_mock
|
||||
assert acc_mock.async_stop.called
|
||||
assert acc_mock.stop.called
|
||||
assert len(homekit.bridge.accessories) == 0
|
||||
|
||||
|
||||
@@ -695,9 +696,11 @@ async def test_homekit_reset_accessories(hass, mock_zeroconf):
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -730,9 +733,12 @@ async def test_homekit_unpair(hass, device_reg, mock_zeroconf):
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
state = homekit.driver.state
|
||||
state.add_paired_client("client1", "any", b"1")
|
||||
@@ -769,9 +775,12 @@ async def test_homekit_unpair_missing_device_id(hass, device_reg, mock_zeroconf)
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
state = homekit.driver.state
|
||||
state.add_paired_client("client1", "any", b"1")
|
||||
@@ -807,6 +816,8 @@ async def test_homekit_unpair_not_homekit_device(hass, device_reg, mock_zeroconf
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
@@ -856,9 +867,12 @@ async def test_homekit_reset_accessories_not_supported(hass, mock_zeroconf):
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -896,9 +910,12 @@ async def test_homekit_reset_accessories_state_missing(hass, mock_zeroconf):
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -935,9 +952,12 @@ async def test_homekit_reset_accessories_not_bridged(hass, mock_zeroconf):
|
||||
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
aid = homekit.aid_storage.get_or_allocate_aid_for_entity_id(entity_id)
|
||||
homekit.bridge.accessories = {aid: acc_mock}
|
||||
homekit.status = STATUS_RUNNING
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -974,7 +994,10 @@ async def test_homekit_reset_single_accessory(hass, mock_zeroconf):
|
||||
homekit.status = STATUS_RUNNING
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
homekit.driver.accessory = acc_mock
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -1008,7 +1031,10 @@ async def test_homekit_reset_single_accessory_unsupported(hass, mock_zeroconf):
|
||||
homekit.status = STATUS_RUNNING
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
homekit.driver.accessory = acc_mock
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -1041,7 +1067,10 @@ async def test_homekit_reset_single_accessory_state_missing(hass, mock_zeroconf)
|
||||
homekit.status = STATUS_RUNNING
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
homekit.driver.accessory = acc_mock
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
@@ -1074,7 +1103,10 @@ async def test_homekit_reset_single_accessory_no_match(hass, mock_zeroconf):
|
||||
homekit.status = STATUS_RUNNING
|
||||
acc_mock = MagicMock()
|
||||
acc_mock.entity_id = entity_id
|
||||
acc_mock.stop = AsyncMock()
|
||||
|
||||
homekit.driver.accessory = acc_mock
|
||||
homekit.driver.aio_stop_event = MagicMock()
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
|
||||
Reference in New Issue
Block a user