Skip to content

Commit

Permalink
Bump zeroconf to 0.129.0 (#105701)
Browse files Browse the repository at this point in the history
* Bump zeroconf to 0.129.0

changelog: python-zeroconf/python-zeroconf@0.128.5...0.129.0

* cleanup typing

* remove redunant lru

* revert type narrowing
  • Loading branch information
bdraco authored Dec 14, 2023
1 parent a16ab0d commit aafdca8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 40 deletions.
16 changes: 3 additions & 13 deletions homeassistant/components/thread/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")):
Expand Down
34 changes: 11 additions & 23 deletions homeassistant/components/zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
)


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -586,27 +583,18 @@ 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,
port=service.port,
hostname=service.server,
type=service.type,
name=service.name,
properties=properties,
properties=service.decoded_properties,
)


Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/zeroconf/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "local_push",
"loggers": ["zeroconf"],
"quality_scale": "internal",
"requirements": ["zeroconf==0.128.5"]
"requirements": ["zeroconf==0.129.0"]
}
2 changes: 1 addition & 1 deletion homeassistant/package_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aafdca8

Please sign in to comment.