Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions zeroconf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1984,20 +1984,33 @@ def get_name(self) -> str:
return self.name[: len(self.name) - len(self.type) - 1]

def update_record(self, zc: 'Zeroconf', now: float, record: Optional[DNSRecord]) -> None:
"""Updates service information from a DNS record."""
if record is None or record.is_expired(now):
return
"""Updates service information from a DNS record.

This method is deprecated and will be removed in a future version.
update_records should be implemented instead.
"""
if record is not None:
self.update_records(zc, now, [record])

self._process_record(record)
def update_records(self, zc: 'Zeroconf', now: float, records: List[DNSRecord]) -> None:
"""Updates service information from a DNS record."""
update_addresses = False
for record in records:
if isinstance(record, DNSService):
update_addresses = True
self._process_record(record, now)

# Only update addresses if the DNSService (.server) has changed
if not isinstance(record, DNSService):
if not update_addresses:
return

for cached_record in self._get_address_records_from_cache(zc):
self._process_record(cached_record)
for record in self._get_address_records_from_cache(zc):
self._process_record(record, now)

def _process_record(self, record: DNSRecord, now: float) -> None:
if record.is_expired(now):
return

def _process_record(self, record: DNSRecord) -> None:
if isinstance(record, DNSAddress):
if record.key == self.server_key and record.address not in self._addresses:
self._addresses.append(record.address)
Expand Down Expand Up @@ -2087,8 +2100,7 @@ def load_from_cache(self, zc: 'Zeroconf') -> bool:
cached_txt_record = zc.cache.get_by_details(self.name, _TYPE_TXT, _CLASS_IN)
if cached_txt_record:
record_updates.append(cached_txt_record)
for record in record_updates:
self.update_record(zc, now, record)
self.update_records(zc, now, record_updates)
return self._is_complete

@property
Expand Down
2 changes: 2 additions & 0 deletions zeroconf/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,8 @@ def test_service_info_rejects_non_matching_updates(self):
info = ServiceInfo(
service_type, service_name, 22, 0, 0, desc, service_server, addresses=[service_address]
)
# Verify backwards compatiblity with calling with None
info.update_record(zc, now, None)
# Matching updates
info.update_record(
zc,
Expand Down