Options to not track wired clients (#25669)

pull/25697/head
Robert Svensson 2019-08-02 23:51:06 +02:00 committed by GitHub
parent a54ade1189
commit 93dfd613aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 0 deletions

View File

@ -13,6 +13,7 @@ from .const import (
CONF_DETECTION_TIME, CONF_DETECTION_TIME,
CONF_DONT_TRACK_CLIENTS, CONF_DONT_TRACK_CLIENTS,
CONF_DONT_TRACK_DEVICES, CONF_DONT_TRACK_DEVICES,
CONF_DONT_TRACK_WIRED_CLIENTS,
CONF_SITE_ID, CONF_SITE_ID,
CONF_SSID_FILTER, CONF_SSID_FILTER,
CONTROLLER_ID, CONTROLLER_ID,
@ -32,6 +33,7 @@ CONTROLLER_SCHEMA = vol.Schema(
), ),
vol.Optional(CONF_DONT_TRACK_CLIENTS): cv.boolean, vol.Optional(CONF_DONT_TRACK_CLIENTS): cv.boolean,
vol.Optional(CONF_DONT_TRACK_DEVICES): cv.boolean, vol.Optional(CONF_DONT_TRACK_DEVICES): cv.boolean,
vol.Optional(CONF_DONT_TRACK_WIRED_CLIENTS): cv.boolean,
vol.Optional(CONF_DETECTION_TIME): vol.All( vol.Optional(CONF_DETECTION_TIME): vol.All(
cv.time_period, cv.positive_timedelta cv.time_period, cv.positive_timedelta
), ),

View File

@ -15,6 +15,7 @@ CONF_BLOCK_CLIENT = "block_client"
CONF_DETECTION_TIME = "detection_time" CONF_DETECTION_TIME = "detection_time"
CONF_DONT_TRACK_CLIENTS = "dont_track_clients" CONF_DONT_TRACK_CLIENTS = "dont_track_clients"
CONF_DONT_TRACK_DEVICES = "dont_track_devices" CONF_DONT_TRACK_DEVICES = "dont_track_devices"
CONF_DONT_TRACK_WIRED_CLIENTS = "dont_track_wired_clients"
CONF_SSID_FILTER = "ssid_filter" CONF_SSID_FILTER = "ssid_filter"
ATTR_MANUFACTURER = "Ubiquiti Networks" ATTR_MANUFACTURER = "Ubiquiti Networks"

View File

@ -30,6 +30,7 @@ from .const import (
CONF_DETECTION_TIME, CONF_DETECTION_TIME,
CONF_DONT_TRACK_CLIENTS, CONF_DONT_TRACK_CLIENTS,
CONF_DONT_TRACK_DEVICES, CONF_DONT_TRACK_DEVICES,
CONF_DONT_TRACK_WIRED_CLIENTS,
CONF_SITE_ID, CONF_SITE_ID,
CONF_SSID_FILTER, CONF_SSID_FILTER,
CONTROLLER_ID, CONTROLLER_ID,
@ -178,6 +179,12 @@ def update_items(controller, async_add_entities, tracked):
): ):
continue continue
if (
controller.unifi_config.get(CONF_DONT_TRACK_WIRED_CLIENTS, False)
and client.is_wired
):
continue
tracked[client_id] = UniFiClientTracker(client, controller) tracked[client_id] = UniFiClientTracker(client, controller)
new_tracked.append(tracked[client_id]) new_tracked.append(tracked[client_id])
LOGGER.debug( LOGGER.debug(

View File

@ -280,3 +280,21 @@ async def test_dont_track_devices(hass, mock_controller):
device_1 = hass.states.get("device_tracker.device_1") device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is None assert device_1 is None
async def test_dont_track_wired_clients(hass, mock_controller):
"""Test dont track wired clients config works."""
mock_controller.mock_client_responses.append([CLIENT_1, CLIENT_2])
mock_controller.mock_device_responses.append({})
mock_controller.unifi_config = {unifi.CONF_DONT_TRACK_WIRED_CLIENTS: True}
await setup_controller(hass, mock_controller)
assert len(mock_controller.mock_requests) == 2
assert len(hass.states.async_all()) == 3
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "not_home"
client_2 = hass.states.get("device_tracker.client_2")
assert client_2 is None