Mark clients away if they have never been seen. (#32222)

pull/32286/head
Jens Nistler 2020-02-27 20:50:34 +01:00 committed by GitHub
parent e695bb55c8
commit ecd076c5e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -200,6 +200,11 @@ class UniFiClientTracker(UniFiClient, ScannerEntity):
else:
self.wired_bug = None
# A client that has never been seen cannot be connected.
if self.client.last_seen is None:
return False
since_last_seen = dt_util.utcnow() - dt_util.utc_from_timestamp(
float(self.client.last_seen)
)

View File

@ -54,6 +54,14 @@ CLIENT_4 = {
"last_seen": 1562600145,
"mac": "00:00:00:00:00:04",
}
CLIENT_5 = {
"essid": "ssid",
"hostname": "client_5",
"ip": "10.0.0.5",
"is_wired": True,
"last_seen": None,
"mac": "00:00:00:00:00:05",
}
DEVICE_1 = {
"board_rev": 3,
@ -111,11 +119,11 @@ async def test_tracked_devices(hass):
controller = await setup_unifi_integration(
hass,
options={CONF_SSID_FILTER: ["ssid"]},
clients_response=[CLIENT_1, CLIENT_2, CLIENT_3, client_4_copy],
clients_response=[CLIENT_1, CLIENT_2, CLIENT_3, CLIENT_5, client_4_copy],
devices_response=[DEVICE_1, DEVICE_2],
known_wireless_clients=(CLIENT_4["mac"],),
)
assert len(hass.states.async_all()) == 6
assert len(hass.states.async_all()) == 7
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
@ -134,6 +142,11 @@ async def test_tracked_devices(hass):
assert client_4 is not None
assert client_4.state == "not_home"
# A client that has never been seen should be marked away.
client_5 = hass.states.get("device_tracker.client_5")
assert client_5 is not None
assert client_5.state == "not_home"
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
assert device_1.state == "not_home"