UniFi - Allow tracking of clients connected to third party APs (#34067)

* Allow disable wired bug work around

* Move small improvements from closed PR #34065

* Fix failing test

* Add new test

* Some extra logging

* Harmonize log outputs

* Add config flow string

* Fix Balloobs comments
This commit is contained in:
Robert Svensson authored and GitHub committed 2020-04-17 08:39:01 +02:00
1 parent 2326a2941e
commit 465eeab553
11 files changed
+145 -64

No files matched your search

+52 -6
View File
@@ -11,6 +11,7 @@ from homeassistant.components import unifi
import homeassistant.components.device_tracker as device_tracker
from homeassistant.components.unifi.const import (
CONF_BLOCK_CLIENT,
CONF_IGNORE_WIRED_BUG,
CONF_SSID_FILTER,
CONF_TRACK_CLIENTS,
CONF_TRACK_DEVICES,
@@ -376,12 +377,18 @@ async def test_option_track_devices(hass):
async def test_option_ssid_filter(hass):
"""Test the SSID filter works."""
controller = await setup_unifi_integration(
hass, options={CONF_SSID_FILTER: ["ssid"]}, clients_response=[CLIENT_3],
)
assert len(hass.states.async_entity_ids("device_tracker")) == 0
controller = await setup_unifi_integration(hass, clients_response=[CLIENT_3])
assert len(hass.states.async_entity_ids("device_tracker")) == 1
client_3 = hass.states.get("device_tracker.client_3")
assert client_3
# Set SSID filter
hass.config_entries.async_update_entry(
controller.config_entry, options={CONF_SSID_FILTER: ["ssid"]},
)
await hass.async_block_till_done()
# SSID filter active
client_3 = hass.states.get("device_tracker.client_3")
assert not client_3
@@ -403,7 +410,6 @@ async def test_option_ssid_filter(hass):
controller.api.message_handler(event)
await hass.async_block_till_done()
# SSID no longer filtered
client_3 = hass.states.get("device_tracker.client_3")
assert client_3.state == "home"
@@ -422,6 +428,7 @@ async def test_wireless_client_go_wired_issue(hass):
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
client_1_client["is_wired"] = True
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
@@ -431,6 +438,7 @@ async def test_wireless_client_go_wired_issue(hass):
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
with patch.object(
unifi.device_tracker.dt_util,
@@ -443,6 +451,7 @@ async def test_wireless_client_go_wired_issue(hass):
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
assert client_1.attributes["is_wired"] is False
client_1_client["is_wired"] = False
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
@@ -452,6 +461,43 @@ async def test_wireless_client_go_wired_issue(hass):
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
async def test_option_ignore_wired_bug(hass):
"""Test option to ignore wired bug."""
client_1_client = copy(CLIENT_1)
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
controller = await setup_unifi_integration(
hass, options={CONF_IGNORE_WIRED_BUG: True}, clients_response=[client_1_client]
)
assert len(hass.states.async_entity_ids("device_tracker")) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
client_1_client["is_wired"] = True
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
event = {"meta": {"message": "sta:sync"}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is True
client_1_client["is_wired"] = False
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
event = {"meta": {"message": "sta:sync"}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
async def test_restoring_client(hass):