Skip to content

Commit

Permalink
Set Netgear device entities to unavailable when the device is not con…
Browse files Browse the repository at this point in the history
…nected (#135362)
  • Loading branch information
lanthaler authored Jan 23, 2025
1 parent 507239c commit 2617575
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions homeassistant/components/netgear/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ async def async_update_device_trackers(self, now=None) -> bool:

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")
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/netgear/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ def __init__(
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."""
Expand Down

0 comments on commit 2617575

Please sign in to comment.