diff --git a/homeassistant/components/thread/discovery.py b/homeassistant/components/thread/discovery.py index 3395353b7bfaff..0f2997986cb199 100644 --- a/homeassistant/components/thread/discovery.py +++ b/homeassistant/components/thread/discovery.py @@ -60,11 +60,7 @@ def try_decode(value: bytes | None) -> str | None: except UnicodeDecodeError: return None - # Service properties are always bytes if they are set from the network. - # For legacy backwards compatibility zeroconf allows properties to be set - # as strings but we never do that so we can safely cast here. - service_properties = cast(dict[bytes, bytes | None], service.properties) - + service_properties = service.properties border_agent_id = service_properties.get(b"id") model_name = try_decode(service_properties.get(b"mn")) network_name = try_decode(service_properties.get(b"nn")) @@ -121,10 +117,7 @@ def async_read_zeroconf_cache(aiozc: AsyncZeroconf) -> list[ThreadRouterDiscover # data is not fully in the cache, so ignore for now continue - # Service properties are always bytes if they are set from the network. - # For legacy backwards compatibility zeroconf allows properties to be set - # as strings but we never do that so we can safely cast here. - service_properties = cast(dict[bytes, bytes | None], info.properties) + service_properties = info.properties if not (xa := service_properties.get(b"xa")): _LOGGER.debug("Ignoring record without xa %s", info) @@ -189,10 +182,7 @@ async def _add_update_service(self, type_: str, name: str): return _LOGGER.debug("_add_update_service %s %s", name, service) - # Service properties are always bytes if they are set from the network. - # For legacy backwards compatibility zeroconf allows properties to be set - # as strings but we never do that so we can safely cast here. - service_properties = cast(dict[bytes, bytes | None], service.properties) + service_properties = service.properties # We need xa and xp, bail out if either is missing if not (xa := service_properties.get(b"xa")): diff --git a/homeassistant/components/zeroconf/__init__.py b/homeassistant/components/zeroconf/__init__.py index bf0984d3989ef0..03662ef4ce6371 100644 --- a/homeassistant/components/zeroconf/__init__.py +++ b/homeassistant/components/zeroconf/__init__.py @@ -128,12 +128,12 @@ class ZeroconfServiceInfo(BaseServiceInfo): @property def host(self) -> str: """Return the host.""" - return _stringify_ip_address(self.ip_address) + return str(self.ip_address) @property def addresses(self) -> list[str]: """Return the addresses.""" - return [_stringify_ip_address(ip_address) for ip_address in self.ip_addresses] + return [str(ip_address) for ip_address in self.ip_addresses] @bind_hass @@ -338,12 +338,13 @@ def _match_against_data( return True -def _match_against_props(matcher: dict[str, str], props: dict[str, str]) -> bool: +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].lower(), matcher[key]) + if key not in props + or not _memorized_fnmatch((props[key] or "").lower(), matcher[key]) ) @@ -467,7 +468,7 @@ def _async_process_service_update( _LOGGER.debug("Failed to get addresses for device %s", name) return _LOGGER.debug("Discovered new device %s %s", name, info) - props: dict[str, str] = info.properties + props: dict[str, str | None] = info.properties domain = None # If we can handle it as a HomeKit discovery, we do that here. @@ -563,10 +564,6 @@ def async_get_homekit_discovery( return None -# matches to the cache in zeroconf itself -_stringify_ip_address = lru_cache(maxsize=256)(str) - - def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None: """Return prepared info from mDNS entries.""" # See https://ietf.org/rfc/rfc6763.html#section-6.4 and @@ -586,19 +583,10 @@ def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None: if not ip_address: return None - # Service properties are always bytes if they are set from the network. - # For legacy backwards compatibility zeroconf allows properties to be set - # as strings but we never do that so we can safely cast here. - service_properties = cast(dict[bytes, bytes | None], service.properties) - - properties: dict[str, Any] = { - k.decode("ascii", "replace"): None - if v is None - else v.decode("utf-8", "replace") - for k, v in service_properties.items() - } - - assert service.server is not None, "server cannot be none if there are addresses" + if TYPE_CHECKING: + assert ( + service.server is not None + ), "server cannot be none if there are addresses" return ZeroconfServiceInfo( ip_address=ip_address, ip_addresses=ip_addresses, @@ -606,7 +594,7 @@ def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None: hostname=service.server, type=service.type, name=service.name, - properties=properties, + properties=service.decoded_properties, ) diff --git a/homeassistant/components/zeroconf/manifest.json b/homeassistant/components/zeroconf/manifest.json index d78f33f0d91611..c4d7cb923bcc36 100644 --- a/homeassistant/components/zeroconf/manifest.json +++ b/homeassistant/components/zeroconf/manifest.json @@ -8,5 +8,5 @@ "iot_class": "local_push", "loggers": ["zeroconf"], "quality_scale": "internal", - "requirements": ["zeroconf==0.128.5"] + "requirements": ["zeroconf==0.129.0"] } diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index f01000d100bb2a..dae1f1d07327e7 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -58,7 +58,7 @@ voluptuous-serialize==2.6.0 voluptuous==0.13.1 webrtc-noise-gain==1.2.3 yarl==1.9.4 -zeroconf==0.128.5 +zeroconf==0.129.0 # Constrain pycryptodome to avoid vulnerability # see https://github.com/home-assistant/core/pull/16238 diff --git a/requirements_all.txt b/requirements_all.txt index f890d3ad9d658a..b7ed653568f871 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2832,7 +2832,7 @@ zamg==0.3.3 zengge==0.2 # homeassistant.components.zeroconf -zeroconf==0.128.5 +zeroconf==0.129.0 # homeassistant.components.zeversolar zeversolar==0.3.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ed309f4ce1329d..855441eecbe936 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -2130,7 +2130,7 @@ yt-dlp==2023.11.16 zamg==0.3.3 # homeassistant.components.zeroconf -zeroconf==0.128.5 +zeroconf==0.129.0 # homeassistant.components.zeversolar zeversolar==0.3.1