Prepare homekit_controller for _hap._udp.local. (#74857)

* Prepare homekit_controller for _hap._udp.local.
This commit is contained in:
Jc2k 2022-07-10 19:50:54 +01:00 committed by GitHub
parent c9aa3c112a
commit 59170d3c54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 7 deletions

View File

@ -8,6 +8,7 @@ from typing import Any
import aiohomekit import aiohomekit
from aiohomekit.exceptions import AuthenticationError from aiohomekit.exceptions import AuthenticationError
from aiohomekit.model import Accessories, CharacteristicsTypes, ServicesTypes from aiohomekit.model import Accessories, CharacteristicsTypes, ServicesTypes
from aiohomekit.utils import domain_supported, domain_to_name
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
@ -203,8 +204,12 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
hkid = properties[zeroconf.ATTR_PROPERTIES_ID] hkid = properties[zeroconf.ATTR_PROPERTIES_ID]
normalized_hkid = normalize_hkid(hkid) normalized_hkid = normalize_hkid(hkid)
# If this aiohomekit doesn't support this particular device, ignore it.
if not domain_supported(discovery_info.name):
return self.async_abort(reason="ignored_model")
model = properties["md"] model = properties["md"]
name = discovery_info.name.replace("._hap._tcp.local.", "") name = domain_to_name(discovery_info.name)
status_flags = int(properties["sf"]) status_flags = int(properties["sf"])
paired = not status_flags & 0x01 paired = not status_flags & 0x01

View File

@ -3,8 +3,8 @@
"name": "HomeKit Controller", "name": "HomeKit Controller",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/homekit_controller", "documentation": "https://www.home-assistant.io/integrations/homekit_controller",
"requirements": ["aiohomekit==0.7.21"], "requirements": ["aiohomekit==0.7.22"],
"zeroconf": ["_hap._tcp.local."], "zeroconf": ["_hap._tcp.local.", "_hap._udp.local."],
"after_dependencies": ["zeroconf"], "after_dependencies": ["zeroconf"],
"codeowners": ["@Jc2k", "@bdraco"], "codeowners": ["@Jc2k", "@bdraco"],
"iot_class": "local_push", "iot_class": "local_push",

View File

@ -167,6 +167,11 @@ ZEROCONF = {
"name": "*z.wave-me*" "name": "*z.wave-me*"
} }
], ],
"_hap._udp.local.": [
{
"domain": "homekit_controller"
}
],
"_homekit._tcp.local.": [ "_homekit._tcp.local.": [
{ {
"domain": "homekit" "domain": "homekit"

View File

@ -168,7 +168,7 @@ aioguardian==2022.03.2
aioharmony==0.2.9 aioharmony==0.2.9
# homeassistant.components.homekit_controller # homeassistant.components.homekit_controller
aiohomekit==0.7.21 aiohomekit==0.7.22
# homeassistant.components.emulated_hue # homeassistant.components.emulated_hue
# homeassistant.components.http # homeassistant.components.http

View File

@ -152,7 +152,7 @@ aioguardian==2022.03.2
aioharmony==0.2.9 aioharmony==0.2.9
# homeassistant.components.homekit_controller # homeassistant.components.homekit_controller
aiohomekit==0.7.21 aiohomekit==0.7.22
# homeassistant.components.emulated_hue # homeassistant.components.emulated_hue
# homeassistant.components.http # homeassistant.components.http

View File

@ -224,7 +224,7 @@ async def device_config_changed(hass, accessories):
host="127.0.0.1", host="127.0.0.1",
addresses=["127.0.0.1"], addresses=["127.0.0.1"],
hostname="mock_hostname", hostname="mock_hostname",
name="TestDevice", name="TestDevice._hap._tcp.local.",
port=8080, port=8080,
properties={ properties={
"md": "TestDevice", "md": "TestDevice",

View File

@ -141,7 +141,7 @@ def get_device_discovery_info(
result = zeroconf.ZeroconfServiceInfo( result = zeroconf.ZeroconfServiceInfo(
host="127.0.0.1", host="127.0.0.1",
hostname=device.description.name, hostname=device.description.name,
name=device.description.name, name=device.description.name + "._hap._tcp.local.",
addresses=["127.0.0.1"], addresses=["127.0.0.1"],
port=8080, port=8080,
properties={ properties={
@ -265,6 +265,23 @@ async def test_pair_already_paired_1(hass, controller):
assert result["reason"] == "already_paired" assert result["reason"] == "already_paired"
async def test_unknown_domain_type(hass, controller):
"""Test that aiohomekit can reject discoveries it doesn't support."""
device = setup_mock_accessory(controller)
# Flag device as already paired
discovery_info = get_device_discovery_info(device)
discovery_info.name = "TestDevice._music._tap.local."
# Device is discovered
result = await hass.config_entries.flow.async_init(
"homekit_controller",
context={"source": config_entries.SOURCE_ZEROCONF},
data=discovery_info,
)
assert result["type"] == "abort"
assert result["reason"] == "ignored_model"
async def test_id_missing(hass, controller): async def test_id_missing(hass, controller):
"""Test id is missing.""" """Test id is missing."""
device = setup_mock_accessory(controller) device = setup_mock_accessory(controller)