Fix last seen not available on certain devices (#25735)
This commit is contained in:
parent
e24d3f15fd
commit
c76531a366
2 changed files with 19 additions and 6 deletions
|
@ -301,11 +301,10 @@ class UniFiDeviceTracker(ScannerEntity):
|
||||||
CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME
|
CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME
|
||||||
)
|
)
|
||||||
|
|
||||||
if (
|
if self.device.last_seen and (
|
||||||
self.device.last_seen
|
dt_util.utcnow() - dt_util.utc_from_timestamp(float(self.device.last_seen))
|
||||||
and dt_util.utcnow()
|
< detection_time
|
||||||
- dt_util.utc_from_timestamp(float(self.device.last_seen))
|
):
|
||||||
) < detection_time:
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -347,6 +346,9 @@ class UniFiDeviceTracker(ScannerEntity):
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the device state attributes."""
|
"""Return the device state attributes."""
|
||||||
|
if not self.device.last_seen:
|
||||||
|
return {}
|
||||||
|
|
||||||
attributes = {}
|
attributes = {}
|
||||||
|
|
||||||
attributes["upgradable"] = self.device.upgradable
|
attributes["upgradable"] = self.device.upgradable
|
||||||
|
|
|
@ -73,6 +73,17 @@ DEVICE_1 = {
|
||||||
"upgradable": False,
|
"upgradable": False,
|
||||||
"version": "4.0.42.10433",
|
"version": "4.0.42.10433",
|
||||||
}
|
}
|
||||||
|
DEVICE_2 = {
|
||||||
|
"board_rev": 3,
|
||||||
|
"device_id": "mock-id",
|
||||||
|
"has_fan": True,
|
||||||
|
"ip": "10.0.1.1",
|
||||||
|
"mac": "00:00:00:00:01:01",
|
||||||
|
"model": "US16P150",
|
||||||
|
"name": "device_1",
|
||||||
|
"type": "usw",
|
||||||
|
"version": "4.0.42.10433",
|
||||||
|
}
|
||||||
|
|
||||||
CONTROLLER_DATA = {
|
CONTROLLER_DATA = {
|
||||||
CONF_HOST: "mock-host",
|
CONF_HOST: "mock-host",
|
||||||
|
@ -167,7 +178,7 @@ async def test_no_clients(hass, mock_controller):
|
||||||
async def test_tracked_devices(hass, mock_controller):
|
async def test_tracked_devices(hass, mock_controller):
|
||||||
"""Test the update_items function with some clients."""
|
"""Test the update_items function with some clients."""
|
||||||
mock_controller.mock_client_responses.append([CLIENT_1, CLIENT_2, CLIENT_3])
|
mock_controller.mock_client_responses.append([CLIENT_1, CLIENT_2, CLIENT_3])
|
||||||
mock_controller.mock_device_responses.append([DEVICE_1])
|
mock_controller.mock_device_responses.append([DEVICE_1, DEVICE_2])
|
||||||
mock_controller.unifi_config = {unifi_dt.CONF_SSID_FILTER: ["ssid"]}
|
mock_controller.unifi_config = {unifi_dt.CONF_SSID_FILTER: ["ssid"]}
|
||||||
|
|
||||||
await setup_controller(hass, mock_controller)
|
await setup_controller(hass, mock_controller)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue