Small cleanup to zeroconf properties matcher (#107342)

* Small cleanup to zeroconf properties matcher

- Switch to dict.items() to avoid dict key lookup
- return early when a match is rejected

* tweak
This commit is contained in:
J. Nick Koston 2024-01-05 23:16:57 -10:00 committed by GitHub
parent 44018a4183
commit 851ad21d11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -321,12 +321,11 @@ async def _async_register_hass_zc_service(
def _match_against_props(matcher: dict[str, str], props: dict[str, str | None]) -> bool:
"""Check a matcher to ensure all values in props."""
return not any(
key
for key in matcher
if key not in props
or not _memorized_fnmatch((props[key] or "").lower(), matcher[key])
)
for key, value in matcher.items():
prop_val = props.get(key)
if prop_val is None or not _memorized_fnmatch(prop_val.lower(), value):
return False
return True
def is_homekit_paired(props: dict[str, Any]) -> bool: