* Refactor zeroconf setup to be async Most of the setup was calling back to async because we were setting up listeners. Since we only need to jump into the executor to create the zeroconf instance, its much faster to setup in async. In testing this cut the setup time in half or better. * partial revert to after_deps
31 lines
985 B
Python
31 lines
985 B
Python
"""HomeKit session fixtures."""
|
|
from pyhap.accessory_driver import AccessoryDriver
|
|
import pytest
|
|
|
|
from homeassistant.components.homekit.const import EVENT_HOMEKIT_CHANGED
|
|
from homeassistant.core import callback as ha_callback
|
|
|
|
from tests.async_mock import patch
|
|
|
|
|
|
@pytest.fixture
|
|
def hk_driver(loop):
|
|
"""Return a custom AccessoryDriver instance for HomeKit accessory init."""
|
|
with patch("pyhap.accessory_driver.Zeroconf"), patch(
|
|
"pyhap.accessory_driver.AccessoryEncoder"
|
|
), patch("pyhap.accessory_driver.HAPServer"), patch(
|
|
"pyhap.accessory_driver.AccessoryDriver.publish"
|
|
), patch(
|
|
"pyhap.accessory_driver.AccessoryDriver.persist"
|
|
):
|
|
yield AccessoryDriver(pincode=b"123-45-678", address="127.0.0.1", loop=loop)
|
|
|
|
|
|
@pytest.fixture
|
|
def events(hass):
|
|
"""Yield caught homekit_changed events."""
|
|
events = []
|
|
hass.bus.async_listen(
|
|
EVENT_HOMEKIT_CHANGED, ha_callback(lambda e: events.append(e))
|
|
)
|
|
yield events
|