UniFi - Support automatic removal of clients (#34307)

This commit is contained in:
Robert Svensson authored and GitHub committed 2020-04-16 15:08:53 -07:00
1 parent abae48c287
commit 374fe47809
11 files changed
+227 -46

No files matched your search

+31 -2
View File
@@ -2,8 +2,8 @@
from copy import copy
from datetime import timedelta
from aiounifi.controller import SIGNAL_CONNECTION_STATE
from aiounifi.websocket import STATE_DISCONNECTED, STATE_RUNNING
from aiounifi.controller import MESSAGE_CLIENT_REMOVED, SIGNAL_CONNECTION_STATE
from aiounifi.websocket import SIGNAL_DATA, STATE_DISCONNECTED, STATE_RUNNING
from asynctest import patch
from homeassistant import config_entries
@@ -180,6 +180,35 @@ async def test_tracked_devices(hass):
assert device_1.state == STATE_UNAVAILABLE
async def test_remove_clients(hass):
"""Test the remove_items function with some clients."""
controller = await setup_unifi_integration(
hass, clients_response=[CLIENT_1, CLIENT_2]
)
assert len(hass.states.async_entity_ids("device_tracker")) == 2
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
wired_client = hass.states.get("device_tracker.wired_client")
assert wired_client is not None
controller.api.websocket._data = {
"meta": {"message": MESSAGE_CLIENT_REMOVED},
"data": [CLIENT_1],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids("device_tracker")) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is None
wired_client = hass.states.get("device_tracker.wired_client")
assert wired_client is not None
async def test_controller_state_change(hass):
"""Verify entities state reflect on controller becoming unavailable."""
controller = await setup_unifi_integration(