Ensure homekit_controller recieves zeroconf c# updates (#35545)

* Ensure homekit_controller recieves zeroconf c# updates

If an integration has a homekit config flow step
homekit controller would not see updates for
devices that were paired with it and would not
rescan for changes.

* Only send updates to homekit controller if the device is paired

This avoids the device showing up a second time.

* remove debug

* fix refactor error
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-05-12 14:59:29 -05:00
1 parent f6b6e2f7d1
commit 16cc4aed06
2 files changed
+84 -11

No files matched your search

+26 -4
View File
@@ -43,6 +43,10 @@ HOMEKIT_TYPE = "_hap._tcp.local."
CONF_DEFAULT_INTERFACE = "default_interface"
DEFAULT_DEFAULT_INTERFACE = False
HOMEKIT_PROPERTIES = "properties"
HOMEKIT_PAIRED_STATUS_FLAG = "sf"
HOMEKIT_MODEL = "md"
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.Schema(
@@ -178,8 +182,26 @@ def setup(hass, config):
_LOGGER.debug("Discovered new device %s %s", name, info)
# If we can handle it as a HomeKit discovery, we do that here.
if service_type == HOMEKIT_TYPE and handle_homekit(hass, info):
return
if service_type == HOMEKIT_TYPE:
handle_homekit(hass, info)
# Continue on here as homekit_controller
# still needs to get updates on devices
# so it can see when the 'c#' field is updated.
#
# We only send updates to homekit_controller
# if the device is already paired in order to avoid
# offering a second discovery for the same device
if (
HOMEKIT_PROPERTIES in info
and HOMEKIT_PAIRED_STATUS_FLAG in info[HOMEKIT_PROPERTIES]
):
try:
if not int(info[HOMEKIT_PROPERTIES][HOMEKIT_PAIRED_STATUS_FLAG]):
return
except ValueError:
# HomeKit pairing status unknown
# likely bad homekit data
return
for domain in ZEROCONF[service_type]:
hass.add_job(
@@ -203,10 +225,10 @@ def handle_homekit(hass, info) -> bool:
Return if discovery was forwarded.
"""
model = None
props = info.get("properties", {})
props = info.get(HOMEKIT_PROPERTIES, {})
for key in props:
if key.lower() == "md":
if key.lower() == HOMEKIT_MODEL:
model = props[key]
break