Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove useless calls in ServiceInfo #1248

Merged
merged 3 commits into from
Sep 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/zeroconf/_services/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,17 @@ def _process_record_threadsafe(self, zc: 'Zeroconf', record: DNSRecord, now: flo
return False

record_key = record.key
if record_key == self.server_key and type(record) is DNSAddress:
record_type = type(record)
if record_key == self.server_key and record_type is DNSAddress:
if TYPE_CHECKING:
assert isinstance(record, DNSAddress)
try:
ip_addr = _cached_ip_addresses(record.address)
except ValueError as ex:
log.warning("Encountered invalid address while processing %s: %s", record, ex)
return False

if type(ip_addr) is IPv4Address:
if self._ipv4_addresses:
self._set_ipv4_addresses_from_cache(zc, now)

ipv4_addresses = self._ipv4_addresses
if ip_addr not in ipv4_addresses:
ipv4_addresses.insert(0, ip_addr)
Expand All @@ -448,9 +448,6 @@ def _process_record_threadsafe(self, zc: 'Zeroconf', record: DNSRecord, now: flo

return False

if not self._ipv6_addresses:
self._set_ipv6_addresses_from_cache(zc, now)

ipv6_addresses = self._ipv6_addresses
if ip_addr not in self._ipv6_addresses:
ipv6_addresses.insert(0, ip_addr)
Expand All @@ -464,13 +461,18 @@ def _process_record_threadsafe(self, zc: 'Zeroconf', record: DNSRecord, now: flo
if record_key != self.key:
return False

if record.type == _TYPE_TXT and type(record) is DNSText:
if record_type is DNSText:
if TYPE_CHECKING:
assert isinstance(record, DNSText)
self._set_text(record.text)
return True

if record.type == _TYPE_SRV and type(record) is DNSService:
if record_type is DNSService:
if TYPE_CHECKING:
assert isinstance(record, DNSService)
old_server_key = self.server_key
self.name = record.name
self._name = record.name
self.key = record.key
self.server = record.server
self.server_key = record.server_key
self.port = record.port
Expand Down Expand Up @@ -577,7 +579,11 @@ def _get_address_records_from_cache_by_type(self, zc: 'Zeroconf', _type: int) ->
"""Get the addresses from the cache."""
if self.server_key is None:
return []
return cast("List[DNSAddress]", zc.cache.get_all_by_details(self.server_key, _type, _CLASS_IN))
if TYPE_CHECKING:
records = cast("List[DNSAddress]", zc.cache.get_all_by_details(self.server_key, _type, _CLASS_IN))
else:
records = zc.cache.get_all_by_details(self.server_key, _type, _CLASS_IN)
return records

def set_server_if_missing(self) -> None:
"""Set the server if it is missing.
Expand Down