Fix instability with HomeKit trigger accessories (#80703)

fixes https://github.com/home-assistant/core/issues/78774
fixes https://github.com/home-assistant/core/issues/81685
This commit is contained in:
J. Nick Koston 2022-11-15 11:41:55 -06:00 committed by GitHub
parent 1331a3771a
commit ade4b62aec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 450 additions and 32 deletions

View file

@ -7,9 +7,17 @@ from homeassistant.components.homekit.const import (
DOMAIN as DOMAIN_HOMEKIT,
EVENT_HOMEKIT_CHANGED,
)
from homeassistant.const import ATTR_ENTITY_ID, ATTR_SERVICE
from homeassistant.config_entries import SOURCE_ZEROCONF, ConfigEntryState
from homeassistant.const import (
ATTR_ENTITY_ID,
ATTR_SERVICE,
EVENT_HOMEASSISTANT_STARTED,
)
from homeassistant.setup import async_setup_component
from .util import PATH_HOMEKIT
from tests.common import MockConfigEntry
from tests.components.logbook.common import MockRow, mock_humanify
@ -52,3 +60,57 @@ async def test_humanify_homekit_changed_event(hass, hk_driver, mock_get_source_i
assert event2["domain"] == DOMAIN_HOMEKIT
assert event2["message"] == "send command set_cover_position to 75 for Window"
assert event2["entity_id"] == "cover.window"
async def test_bridge_with_triggers(
hass, hk_driver, mock_async_zeroconf, entity_reg, caplog
):
"""Test we can setup a bridge with triggers and we ignore numeric states.
Since numeric states are not supported by HomeKit as they require
an above or below additional configuration which we have no way
to input, we ignore them.
"""
assert await async_setup_component(hass, "demo", {"demo": {}})
await hass.async_block_till_done()
entry = entity_reg.async_get("cover.living_room_window")
assert entry is not None
device_id = entry.device_id
entry = MockConfigEntry(
domain=DOMAIN_HOMEKIT,
source=SOURCE_ZEROCONF,
data={
"name": "HASS Bridge",
"port": 12345,
},
options={
"filter": {
"exclude_domains": [],
"exclude_entities": [],
"include_domains": [],
"include_entities": ["cover.living_room_window"],
},
"exclude_accessory_mode": True,
"mode": "bridge",
"devices": [device_id],
},
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.network.async_get_source_ip", return_value="1.2.3.4"
), patch(f"{PATH_HOMEKIT}.async_port_is_available", return_value=True):
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASSISTANT_STARTED)
await hass.async_block_till_done()
assert entry.state == ConfigEntryState.LOADED
await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert (
"requires additional inputs which are not supported by HomeKit" in caplog.text
)