mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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:
parent
91c47264b5
commit
bc7624b417
@ -93,7 +93,11 @@ async def async_remove_clients(hass, data) -> None:
|
|||||||
|
|
||||||
for client in controller.api.clients_all.values():
|
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
|
continue
|
||||||
|
|
||||||
if any({client.fixed_ip, client.hostname, client.name}):
|
if any({client.fixed_ip, client.hostname, client.name}):
|
||||||
|
@ -197,6 +197,9 @@ async def test_reconnect_wired_client(hass, aioclient_mock):
|
|||||||
async def test_remove_clients(hass, aioclient_mock):
|
async def test_remove_clients(hass, aioclient_mock):
|
||||||
"""Verify removing different variations of clients work."""
|
"""Verify removing different variations of clients work."""
|
||||||
clients = [
|
clients = [
|
||||||
|
{
|
||||||
|
"mac": "00:00:00:00:00:00",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"first_seen": 100,
|
"first_seen": 100,
|
||||||
"last_seen": 500,
|
"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)
|
await hass.services.async_call(UNIFI_DOMAIN, SERVICE_REMOVE_CLIENTS, blocking=True)
|
||||||
assert aioclient_mock.mock_calls[0][2] == {
|
assert aioclient_mock.mock_calls[0][2] == {
|
||||||
"cmd": "forget-sta",
|
"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)
|
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user