Set Netgear device entities to unavailable when the device is not connected (#135362)

This commit is contained in:
Markus Lanthaler 2025-01-23 20:23:03 +01:00 committed by GitHub
parent 507239c661
commit 2617575e18
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -210,6 +210,12 @@ class NetgearRouter:
for device in self.devices.values():
device["active"] = now - device["last_seen"] <= self._consider_home
if not device["active"]:
device["link_rate"] = None
device["signal"] = None
device["ip"] = None
device["ssid"] = None
device["conn_ap_mac"] = None
if new_device:
_LOGGER.debug("Netgear tracker: new device found")

View File

@ -344,6 +344,11 @@ class NetgearSensorEntity(NetgearDeviceEntity, SensorEntity):
self._attr_unique_id = f"{self._mac}-{attribute}"
self._state = device.get(attribute)
@property
def available(self) -> bool:
"""Return if entity is available."""
return super().available and self._device.get(self._attribute) is not None
@property
def native_value(self):
"""Return the state of the sensor."""