Fix KeyError during call to homekit.unpair (#63627)

This commit is contained in:
J. Nick Koston 2022-01-07 08:47:14 -10:00 committed by GitHub
parent 1ea3a17d89
commit 945477a482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -708,6 +708,11 @@ class HomeKit:
"""Remove all pairings for an accessory so it can be repaired."""
state = self.driver.state
for client_uuid in list(state.paired_clients):
# We need to check again since removing a single client
# can result in removing all the clients that the client
# granted access to if it was an admin, otherwise
# remove_paired_client can generate a KeyError
if client_uuid in state.paired_clients:
state.remove_paired_client(client_uuid)
self.driver.async_persist()
self.driver.async_update_advertisement()

View File

@ -679,6 +679,11 @@ async def test_homekit_unpair(hass, device_reg, mock_async_zeroconf):
state = homekit.driver.state
state.add_paired_client("client1", "any", b"1")
state.add_paired_client("client2", "any", b"0")
state.add_paired_client("client3", "any", b"1")
state.add_paired_client("client4", "any", b"0")
state.add_paired_client("client5", "any", b"0")
formatted_mac = device_registry.format_mac(state.mac)
hk_bridge_dev = device_reg.async_get_device(
{}, {(device_registry.CONNECTION_NETWORK_MAC, formatted_mac)}