mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Remove _raw from zeroconf properties (#94615)
* Remove _raw from zeroconf properties This was added in #31059 but it appears it was never used. To preserve backwards compatibility, properties are still decoded but utf-8 errors are replaced instead of dropped * Remove _raw from zeroconf properties This was added in #31059 but it appears it was never used. To preserve backwards compatibility, properties are still decoded but utf-8 errors are replaced instead of dropped
This commit is contained in:
parent
7b3f100efb
commit
e0ae7a31fe
@ -581,26 +581,9 @@ def _stringify_ip_address(ip_addr: IPv4Address | IPv6Address) -> str:
|
||||
|
||||
def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None:
|
||||
"""Return prepared info from mDNS entries."""
|
||||
properties: dict[str, Any] = {"_raw": {}}
|
||||
|
||||
for key, value in service.properties.items():
|
||||
# See https://ietf.org/rfc/rfc6763.html#section-6.4 and
|
||||
# https://ietf.org/rfc/rfc6763.html#section-6.5 for expected encodings
|
||||
# for property keys and values
|
||||
try:
|
||||
key = key.decode("ascii")
|
||||
except UnicodeDecodeError:
|
||||
_LOGGER.debug(
|
||||
"Ignoring invalid key provided by [%s]: %s", service.name, key
|
||||
)
|
||||
continue
|
||||
|
||||
properties["_raw"][key] = value
|
||||
|
||||
with suppress(UnicodeDecodeError):
|
||||
if isinstance(value, bytes):
|
||||
properties[key] = value.decode("utf-8")
|
||||
|
||||
if not (ip_addresses := service.ip_addresses_by_version(IPVersion.All)):
|
||||
return None
|
||||
host: str | None = None
|
||||
@ -610,6 +593,12 @@ def info_from_service(service: AsyncServiceInfo) -> ZeroconfServiceInfo | None:
|
||||
break
|
||||
if not host:
|
||||
return None
|
||||
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"
|
||||
return ZeroconfServiceInfo(
|
||||
|
@ -910,13 +910,11 @@ async def test_info_from_service_non_utf8(hass: HomeAssistant) -> None:
|
||||
info = zeroconf.info_from_service(
|
||||
get_service_info_mock(service_type, f"test.{service_type}")
|
||||
)
|
||||
raw_info = info.properties.pop("_raw", False)
|
||||
assert raw_info
|
||||
assert len(raw_info) == len(PROPERTIES) - 1
|
||||
assert NON_ASCII_KEY not in raw_info
|
||||
assert len(info.properties) <= len(raw_info)
|
||||
assert "non-utf8-value" not in info.properties
|
||||
assert raw_info["non-utf8-value"] is NON_UTF8_VALUE
|
||||
assert NON_ASCII_KEY.decode("ascii", "replace") in info.properties
|
||||
assert "non-utf8-value" in info.properties
|
||||
assert info.properties["non-utf8-value"] == NON_UTF8_VALUE.decode(
|
||||
"utf-8", "replace"
|
||||
)
|
||||
|
||||
|
||||
async def test_info_from_service_with_addresses(hass: HomeAssistant) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user