diff --git a/homeassistant/components/device_tracker/config_entry.py b/homeassistant/components/device_tracker/config_entry.py index 05edfbad91d..7d8d0791b4d 100644 --- a/homeassistant/components/device_tracker/config_entry.py +++ b/homeassistant/components/device_tracker/config_entry.py @@ -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