Fix last seen not available on certain devices (#25735)

pull/25756/head
Robert Svensson 2019-08-06 23:55:36 +02:00 committed by Paulus Schoutsen
parent 52de2f4ffb
commit 609118d3ac
2 changed files with 19 additions and 6 deletions

View File

@ -301,11 +301,10 @@ class UniFiDeviceTracker(ScannerEntity):
CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME
)
if (
self.device.last_seen
and dt_util.utcnow()
- dt_util.utc_from_timestamp(float(self.device.last_seen))
) < detection_time:
if self.device.last_seen and (
dt_util.utcnow() - dt_util.utc_from_timestamp(float(self.device.last_seen))
< detection_time
):
return True
return False
@ -347,6 +346,9 @@ class UniFiDeviceTracker(ScannerEntity):
@property
def device_state_attributes(self):
"""Return the device state attributes."""
if not self.device.last_seen:
return {}
attributes = {}
attributes["upgradable"] = self.device.upgradable

View File

@ -73,6 +73,17 @@ DEVICE_1 = {
"upgradable": False,
"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 = {
CONF_HOST: "mock-host",
@ -167,7 +178,7 @@ async def test_no_clients(hass, mock_controller):
async def test_tracked_devices(hass, mock_controller):
"""Test the update_items function with some clients."""
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"]}
await setup_controller(hass, mock_controller)