Add manufacturer matching support to zeroconf (#48810)

We plan on matching with _airplay which means we need
to able to limit to specific manufacturers to avoid
generating flows for integrations with the wrong
manufacturer
This commit is contained in:
J. Nick Koston 2021-04-08 09:03:10 -10:00 committed by GitHub
parent c2d98f1905
commit 493bd4cdca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 99 additions and 1 deletions

View file

@ -279,6 +279,13 @@ async def _async_start_zeroconf_browser(
else:
uppercase_mac = None
if "manufacturer" in info["properties"]:
lowercase_manufacturer: str | None = info["properties"][
"manufacturer"
].lower()
else:
lowercase_manufacturer = None
# Not all homekit types are currently used for discovery
# so not all service type exist in zeroconf_types
for entry in zeroconf_types.get(service_type, []):
@ -295,6 +302,14 @@ async def _async_start_zeroconf_browser(
and not fnmatch.fnmatch(lowercase_name, entry["name"])
):
continue
if (
lowercase_manufacturer is not None
and "manufacturer" in entry
and not fnmatch.fnmatch(
lowercase_manufacturer, entry["manufacturer"]
)
):
continue
hass.add_job(
hass.config_entries.flow.async_init(