mirror of
https://github.com/home-assistant/core.git
synced 2025-11-16 06:20:07 +00:00
Update homekit_controller to use the new typed discovery data (#66462)
This commit is contained in:
@@ -36,8 +36,6 @@ HOMEKIT_IGNORE = [
|
||||
|
||||
PAIRING_FILE = "pairing.json"
|
||||
|
||||
MDNS_SUFFIX = "._hap._tcp.local."
|
||||
|
||||
PIN_FORMAT = re.compile(r"^(\d{3})-{0,1}(\d{2})-{0,1}(\d{3})$")
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -113,9 +111,10 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
if user_input is not None:
|
||||
key = user_input["device"]
|
||||
self.hkid = self.devices[key].device_id
|
||||
self.model = self.devices[key].info["md"]
|
||||
self.name = key[: -len(MDNS_SUFFIX)] if key.endswith(MDNS_SUFFIX) else key
|
||||
self.hkid = self.devices[key].description.id
|
||||
self.model = self.devices[key].description.model
|
||||
self.name = self.devices[key].description.name
|
||||
|
||||
await self.async_set_unique_id(
|
||||
normalize_hkid(self.hkid), raise_on_progress=False
|
||||
)
|
||||
@@ -127,12 +126,10 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
self.devices = {}
|
||||
|
||||
async for host in self.controller.async_discover():
|
||||
status_flags = int(host.info["sf"])
|
||||
paired = not status_flags & 0x01
|
||||
if paired:
|
||||
async for discovery in self.controller.async_discover():
|
||||
if discovery.paired:
|
||||
continue
|
||||
self.devices[host.info["name"]] = host
|
||||
self.devices[discovery.description.name] = discovery
|
||||
|
||||
if not self.devices:
|
||||
return self.async_abort(reason="no_devices")
|
||||
@@ -158,9 +155,9 @@ class HomekitControllerFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
except aiohomekit.AccessoryNotFoundError:
|
||||
return self.async_abort(reason="accessory_not_found_error")
|
||||
|
||||
self.name = device.info["name"].replace("._hap._tcp.local.", "")
|
||||
self.model = device.info["md"]
|
||||
self.hkid = normalize_hkid(device.info["id"])
|
||||
self.name = device.description.name
|
||||
self.model = device.description.model
|
||||
self.hkid = device.description.id
|
||||
|
||||
return self._async_step_pair_show_form()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user