Fix UniFi remove client service if time stamps are not integers (#63998)

* Only calculate total time if first and last seen are ints, else remove client

* Update homeassistant/components/unifi/services.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Update homeassistant/components/unifi/services.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Robert Svensson 2022-01-13 08:15:40 +01:00 committed by GitHub
parent 91c47264b5
commit bc7624b417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -93,7 +93,11 @@ async def async_remove_clients(hass, data) -> None:
for client in controller.api.clients_all.values():
if client.last_seen - client.first_seen > 900:
if (
client.last_seen
and client.first_seen
and client.last_seen - client.first_seen > 900
):
continue
if any({client.fixed_ip, client.hostname, client.name}):

View File

@ -197,6 +197,9 @@ async def test_reconnect_wired_client(hass, aioclient_mock):
async def test_remove_clients(hass, aioclient_mock):
"""Verify removing different variations of clients work."""
clients = [
{
"mac": "00:00:00:00:00:00",
},
{
"first_seen": 100,
"last_seen": 500,
@ -239,7 +242,7 @@ async def test_remove_clients(hass, aioclient_mock):
await hass.services.async_call(UNIFI_DOMAIN, SERVICE_REMOVE_CLIENTS, blocking=True)
assert aioclient_mock.mock_calls[0][2] == {
"cmd": "forget-sta",
"macs": ["00:00:00:00:00:01"],
"macs": ["00:00:00:00:00:00", "00:00:00:00:00:01"],
}
assert await hass.config_entries.async_unload(config_entry.entry_id)