Only lookup hostname/ip_address/mac_address once in device_tracker (#96984)

This commit is contained in:
J. Nick Koston 2023-07-21 00:07:06 -05:00 committed by GitHub
parent b504665b56
commit 28ff173f16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -405,13 +405,13 @@ class ScannerEntity(BaseTrackerEntity):
@property
def state_attributes(self) -> dict[str, StateType]:
"""Return the device state attributes."""
attr: dict[str, StateType] = {}
attr.update(super().state_attributes)
if self.ip_address:
attr[ATTR_IP] = self.ip_address
if self.mac_address is not None:
attr[ATTR_MAC] = self.mac_address
if self.hostname is not None:
attr[ATTR_HOST_NAME] = self.hostname
attr = super().state_attributes
if ip_address := self.ip_address:
attr[ATTR_IP] = ip_address
if (mac_address := self.mac_address) is not None:
attr[ATTR_MAC] = mac_address
if (hostname := self.hostname) is not None:
attr[ATTR_HOST_NAME] = hostname
return attr