From 851ad21d116f6964179da718d85bb3d67bfa06a8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 5 Jan 2024 23:16:57 -1000 Subject: [PATCH] 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 --- homeassistant/components/zeroconf/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index e12a7599d4d..2e058c4067c 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -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: