Only read HomeKit service/chars from disk once (#70354)

pull/70391/head
J. Nick Koston 2022-04-21 10:54:44 -10:00 committed by GitHub
parent f1b400feaf
commit 034ba7d3ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -12,6 +12,7 @@ from uuid import UUID
from aiohttp import web
from pyhap.const import STANDALONE_AID
from pyhap.loader import get_loader
import voluptuous as vol
from zeroconf.asyncio import AsyncZeroconf
@ -204,6 +205,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the HomeKit from yaml."""
hass.data.setdefault(DOMAIN, {})[PERSIST_LOCK] = asyncio.Lock()
# Initialize the loader before loading entries to ensure
# there is no race where multiple entries try to load it
# at the same time.
await hass.async_add_executor_job(get_loader)
_async_register_events_and_services(hass)
if DOMAIN not in config:
@ -516,6 +522,7 @@ class HomeKit:
advertised_address=self._advertise_ip,
async_zeroconf_instance=async_zeroconf_instance,
zeroconf_server=f"{uuid}-hap.local.",
loader=get_loader(),
)
# If we do not load the mac address will be wrong

View File

@ -218,6 +218,7 @@ async def test_homekit_setup(hass, hk_driver, mock_async_zeroconf):
advertised_address=None,
async_zeroconf_instance=zeroconf_mock,
zeroconf_server=f"{uuid}-hap.local.",
loader=ANY,
)
assert homekit.driver.safe_mode is False
@ -259,6 +260,7 @@ async def test_homekit_setup_ip_address(hass, hk_driver, mock_async_zeroconf):
advertised_address=None,
async_zeroconf_instance=mock_async_zeroconf,
zeroconf_server=f"{uuid}-hap.local.",
loader=ANY,
)
@ -300,6 +302,7 @@ async def test_homekit_setup_advertise_ip(hass, hk_driver, mock_async_zeroconf):
advertised_address="192.168.1.100",
async_zeroconf_instance=async_zeroconf_instance,
zeroconf_server=f"{uuid}-hap.local.",
loader=ANY,
)