Use ZeroconfServiceInfo in homekit_controller (#59979)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d6c5aaa0cb
commit
982f2065c8
2 changed files with 38 additions and 31 deletions
|
@ -9,6 +9,7 @@ import voluptuous as vol
|
|||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.device_registry import (
|
||||
CONNECTION_NETWORK_MAC,
|
||||
async_get_registry as async_get_device_registry,
|
||||
|
@ -157,13 +158,13 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
continue
|
||||
record = device.info
|
||||
return await self.async_step_zeroconf(
|
||||
{
|
||||
"host": record["address"],
|
||||
"port": record["port"],
|
||||
"hostname": record["name"],
|
||||
"type": "_hap._tcp.local.",
|
||||
"name": record["name"],
|
||||
"properties": {
|
||||
zeroconf.ZeroconfServiceInfo(
|
||||
host=record["address"],
|
||||
port=record["port"],
|
||||
hostname=record["name"],
|
||||
type="_hap._tcp.local.",
|
||||
name=record["name"],
|
||||
properties={
|
||||
"md": record["md"],
|
||||
"pv": record["pv"],
|
||||
"id": unique_id,
|
||||
|
@ -174,7 +175,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
"sf": record["sf"],
|
||||
"sh": "",
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
return self.async_abort(reason="no_devices")
|
||||
|
@ -196,7 +197,9 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
return False
|
||||
|
||||
async def async_step_zeroconf(self, discovery_info):
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||
) -> FlowResult:
|
||||
"""Handle a discovered HomeKit accessory.
|
||||
|
||||
This flow is triggered by the discovery component.
|
||||
|
@ -205,7 +208,8 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# homekit_python has code to do this, but not in a form we can
|
||||
# easily use, so do the bare minimum ourselves here instead.
|
||||
properties = {
|
||||
key.lower(): value for (key, value) in discovery_info["properties"].items()
|
||||
key.lower(): value
|
||||
for (key, value) in discovery_info[zeroconf.ATTR_PROPERTIES].items()
|
||||
}
|
||||
|
||||
if "id" not in properties:
|
||||
|
@ -221,7 +225,7 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# It changes if a device is factory reset.
|
||||
hkid = properties["id"]
|
||||
model = properties["md"]
|
||||
name = discovery_info["name"].replace("._hap._tcp.local.", "")
|
||||
name = discovery_info[zeroconf.ATTR_NAME].replace("._hap._tcp.local.", "")
|
||||
status_flags = int(properties["sf"])
|
||||
paired = not status_flags & 0x01
|
||||
|
||||
|
@ -239,8 +243,8 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
# Set unique-id and error out if it's already configured
|
||||
existing_entry = await self.async_set_unique_id(normalize_hkid(hkid))
|
||||
updated_ip_port = {
|
||||
"AccessoryIP": discovery_info["host"],
|
||||
"AccessoryPort": discovery_info["port"],
|
||||
"AccessoryIP": discovery_info[zeroconf.ATTR_HOST],
|
||||
"AccessoryPort": discovery_info[zeroconf.ATTR_PORT],
|
||||
}
|
||||
|
||||
# If the device is already paired and known to us we should monitor c#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue