diff --git a/homeassistant/components/unifi/services.py b/homeassistant/components/unifi/services.py index c1a6bdd3a53..ecf7c33c7ba 100644 --- a/homeassistant/components/unifi/services.py +++ b/homeassistant/components/unifi/services.py @@ -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}): diff --git a/tests/components/unifi/test_services.py b/tests/components/unifi/test_services.py index 8fe41d7a856..b483e789f96 100644 --- a/tests/components/unifi/test_services.py +++ b/tests/components/unifi/test_services.py @@ -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)