Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniFi - option to not track wired clients #25669

Merged
merged 1 commit into from Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions homeassistant/components/unifi/__init__.py
Expand Up @@ -13,6 +13,7 @@
CONF_DETECTION_TIME,
CONF_DONT_TRACK_CLIENTS,
CONF_DONT_TRACK_DEVICES,
CONF_DONT_TRACK_WIRED_CLIENTS,
CONF_SITE_ID,
CONF_SSID_FILTER,
CONTROLLER_ID,
Expand All @@ -32,6 +33,7 @@
),
vol.Optional(CONF_DONT_TRACK_CLIENTS): 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(
cv.time_period, cv.positive_timedelta
),
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/unifi/const.py
Expand Up @@ -15,6 +15,7 @@
CONF_DETECTION_TIME = "detection_time"
CONF_DONT_TRACK_CLIENTS = "dont_track_clients"
CONF_DONT_TRACK_DEVICES = "dont_track_devices"
CONF_DONT_TRACK_WIRED_CLIENTS = "dont_track_wired_clients"
CONF_SSID_FILTER = "ssid_filter"

ATTR_MANUFACTURER = "Ubiquiti Networks"
7 changes: 7 additions & 0 deletions homeassistant/components/unifi/device_tracker.py
Expand Up @@ -30,6 +30,7 @@
CONF_DETECTION_TIME,
CONF_DONT_TRACK_CLIENTS,
CONF_DONT_TRACK_DEVICES,
CONF_DONT_TRACK_WIRED_CLIENTS,
CONF_SITE_ID,
CONF_SSID_FILTER,
CONTROLLER_ID,
Expand Down Expand Up @@ -178,6 +179,12 @@ def update_items(controller, async_add_entities, tracked):
):
continue

if (
controller.unifi_config.get(CONF_DONT_TRACK_WIRED_CLIENTS, False)
and client.is_wired
):
continue

tracked[client_id] = UniFiClientTracker(client, controller)
new_tracked.append(tracked[client_id])
LOGGER.debug(
Expand Down
18 changes: 18 additions & 0 deletions tests/components/unifi/test_device_tracker.py
Expand Up @@ -280,3 +280,21 @@ async def test_dont_track_devices(hass, mock_controller):

device_1 = hass.states.get("device_tracker.device_1")
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