Dont rely on config flow to monitor homekit_controller c# changes (#76861)

This commit is contained in:
Jc2k 2022-08-20 21:58:59 +01:00 committed by GitHub
parent 8b1713a691
commit eb0828efdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 36 additions and 83 deletions

View file

@ -11,10 +11,9 @@ from unittest import mock
from aiohomekit.model import Accessories, AccessoriesState, Accessory
from aiohomekit.testing import FakeController, FakePairing
from aiohomekit.zeroconf import HomeKitService
from homeassistant.components import zeroconf
from homeassistant.components.device_automation import DeviceAutomationType
from homeassistant.components.homekit_controller import config_flow
from homeassistant.components.homekit_controller.const import (
CONTROLLER,
DOMAIN,
@ -22,6 +21,7 @@ from homeassistant.components.homekit_controller.const import (
IDENTIFIER_ACCESSORY_ID,
IDENTIFIER_SERIAL_NUMBER,
)
from homeassistant.components.homekit_controller.utils import async_get_controller
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, State, callback
from homeassistant.helpers import device_registry as dr, entity_registry as er
@ -175,12 +175,11 @@ async def setup_platform(hass):
config = {"discovery": {}}
with mock.patch(
"homeassistant.components.homekit_controller.utils.Controller"
) as controller:
fake_controller = controller.return_value = FakeController()
"homeassistant.components.homekit_controller.utils.Controller", FakeController
):
await async_setup_component(hass, DOMAIN, config)
return fake_controller
return await async_get_controller(hass)
async def setup_test_accessories(hass, accessories):
@ -228,31 +227,24 @@ async def device_config_changed(hass, accessories):
pairing._accessories_state = AccessoriesState(
accessories_obj, pairing.config_num + 1
)
discovery_info = zeroconf.ZeroconfServiceInfo(
host="127.0.0.1",
addresses=["127.0.0.1"],
hostname="mock_hostname",
name="TestDevice._hap._tcp.local.",
port=8080,
properties={
"md": "TestDevice",
"id": "00:00:00:00:00:00",
"c#": "2",
"sf": "0",
},
type="mock_type",
pairing._async_description_update(
HomeKitService(
name="TestDevice.local",
id="00:00:00:00:00:00",
model="",
config_num=2,
state_num=3,
feature_flags=0,
status_flags=0,
category=1,
protocol_version="1.0",
type="_hap._tcp.local.",
address="127.0.0.1",
addresses=["127.0.0.1"],
port=8080,
)
)
# Config Flow will abort and notify us if the discovery event is of
# interest - in this case c# has incremented
flow = config_flow.HomekitControllerFlowHandler()
flow.hass = hass
flow.context = {}
result = await flow.async_step_zeroconf(discovery_info)
assert result["type"] == "abort"
assert result["reason"] == "already_configured"
# Wait for services to reconfigure
await hass.async_block_till_done()
await hass.async_block_till_done()