UniFi - Improve signalling and handling of adding new entities (#34925)

* Change signalling and handling of adding devices

* Bump aiounifi to v19
Use the proper variable for roamradio
This commit is contained in:
Robert Svensson authored and GitHub committed 2020-05-04 19:29:49 +02:00
1 parent dbf383f713
commit c5ce95ff06
9 files changed
+312 -109

No files matched your search

+56 -9
View File
@@ -1,7 +1,7 @@
"""UniFi POE control platform tests."""
"""UniFi switch platform tests."""
from copy import deepcopy
from aiounifi.controller import MESSAGE_CLIENT_REMOVED
from aiounifi.controller import MESSAGE_CLIENT_REMOVED, MESSAGE_EVENT
from aiounifi.websocket import SIGNAL_DATA
from homeassistant import config_entries
@@ -197,6 +197,35 @@ UNBLOCKED = {
"oui": "Producer",
}
EVENT_BLOCKED_CLIENT_CONNECTED = {
"user": BLOCKED["mac"],
"radio": "na",
"channel": "44",
"hostname": BLOCKED["hostname"],
"key": "EVT_WU_Connected",
"subsystem": "wlan",
"site_id": "name",
"time": 1587753456179,
"datetime": "2020-04-24T18:37:36Z",
"msg": f'User{[BLOCKED["mac"]]} has connected."',
"_id": "5ea331fa30c49e00f90ddc1a",
}
EVENT_CLIENT_2_CONNECTED = {
"user": CLIENT_2["mac"],
"radio": "na",
"channel": "44",
"hostname": CLIENT_2["hostname"],
"key": "EVT_WU_Connected",
"subsystem": "wlan",
"site_id": "name",
"time": 1587753456179,
"datetime": "2020-04-24T18:37:36Z",
"msg": f'User{[CLIENT_2["mac"]]} has connected."',
"_id": "5ea331fa30c49e00f90ddc1a",
}
async def test_platform_manually_configured(hass):
"""Test that we do not discover anything or try to set up a controller."""
@@ -360,7 +389,16 @@ async def test_new_client_discovered_on_block_control(hass):
"meta": {"message": "sta:sync"},
"data": [BLOCKED],
}
controller.api.session_handler("data")
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 0
controller.api.websocket._data = {
"meta": {"message": MESSAGE_EVENT},
"data": [EVENT_BLOCKED_CLIENT_CONNECTED],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 1
@@ -423,9 +461,22 @@ async def test_new_client_discovered_on_poe_control(hass):
"meta": {"message": "sta:sync"},
"data": [CLIENT_2],
}
controller.api.session_handler("data")
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 1
controller.api.websocket._data = {
"meta": {"message": MESSAGE_EVENT},
"data": [EVENT_CLIENT_2_CONNECTED],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(SWITCH_DOMAIN)) == 2
switch_2 = hass.states.get("switch.poe_client_2")
assert switch_2 is not None
# Calling a service will trigger the updates to run
await hass.services.async_call(
SWITCH_DOMAIN, "turn_off", {"entity_id": "switch.poe_client_1"}, blocking=True
)
@@ -453,10 +504,6 @@ async def test_new_client_discovered_on_poe_control(hass):
"path": "/rest/device/mock-id",
}
switch_2 = hass.states.get("switch.poe_client_2")
assert switch_2 is not None
assert switch_2.state == "on"
async def test_ignore_multiple_poe_clients_on_same_port(hass):
"""Ignore when there are multiple POE driven clients on same port.