UniFi - Support automatic removal of clients (#34307)
This commit is contained in:
1 parent
abae48c287
commit
374fe47809
11 files changed
+227
-46
No files matched your search
@@ -1,6 +1,9 @@
|
||||
"""UniFi POE control platform tests."""
|
||||
from copy import deepcopy
|
||||
|
||||
from aiounifi.controller import MESSAGE_CLIENT_REMOVED
|
||||
from aiounifi.websocket import SIGNAL_DATA
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import unifi
|
||||
import homeassistant.components.switch as switch
|
||||
@@ -173,6 +176,7 @@ BLOCKED = {
|
||||
"ip": "10.0.0.1",
|
||||
"is_guest": False,
|
||||
"is_wired": False,
|
||||
"last_seen": 1562600145,
|
||||
"mac": "00:00:00:00:01:01",
|
||||
"name": "Block Client 1",
|
||||
"noted": True,
|
||||
@@ -184,6 +188,7 @@ UNBLOCKED = {
|
||||
"ip": "10.0.0.2",
|
||||
"is_guest": False,
|
||||
"is_wired": True,
|
||||
"last_seen": 1562600145,
|
||||
"mac": "00:00:00:00:01:02",
|
||||
"name": "Block Client 2",
|
||||
"noted": True,
|
||||
@@ -300,6 +305,38 @@ async def test_switches(hass):
|
||||
}
|
||||
|
||||
|
||||
async def test_remove_switches(hass):
|
||||
"""Test the update_items function with some clients."""
|
||||
controller = await setup_unifi_integration(
|
||||
hass,
|
||||
options={CONF_BLOCK_CLIENT: [UNBLOCKED["mac"]]},
|
||||
clients_response=[CLIENT_1, UNBLOCKED],
|
||||
devices_response=[DEVICE_1],
|
||||
)
|
||||
assert len(hass.states.async_entity_ids("switch")) == 2
|
||||
|
||||
poe_switch = hass.states.get("switch.poe_client_1")
|
||||
assert poe_switch is not None
|
||||
|
||||
block_switch = hass.states.get("switch.block_client_2")
|
||||
assert block_switch is not None
|
||||
|
||||
controller.api.websocket._data = {
|
||||
"meta": {"message": MESSAGE_CLIENT_REMOVED},
|
||||
"data": [CLIENT_1, UNBLOCKED],
|
||||
}
|
||||
controller.api.session_handler(SIGNAL_DATA)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids("switch")) == 0
|
||||
|
||||
poe_switch = hass.states.get("switch.poe_client_1")
|
||||
assert poe_switch is None
|
||||
|
||||
block_switch = hass.states.get("switch.block_client_2")
|
||||
assert block_switch is None
|
||||
|
||||
|
||||
async def test_new_client_discovered_on_block_control(hass):
|
||||
"""Test if 2nd update has a new client."""
|
||||
controller = await setup_unifi_integration(
|
||||
|
||||
Reference in new issue
Block a user