Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions homeassistant/components/unifi/.translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,26 @@
},
"options": {
"step": {
"init": {
"data": {}
},
"device_tracker": {
"data": {
"detection_time": "Time in seconds from last seen until considered away",
"ssid_filter": "Select SSIDs to track wireless clients on",
"track_clients": "Track network clients",
"track_devices": "Track network devices (Ubiquiti devices)",
"track_wired_clients": "Include wired network clients"
}
},
"description": "Configure device tracking",
"title": "UniFi options"
},
"statistics_sensors": {
"data": {
"allow_bandwidth_sensors": "Create bandwidth usage sensors for network clients"
}
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
},
"description": "Configure statistics sensors",
"title": "UniFi options"
}
}
}
Expand Down
39 changes: 16 additions & 23 deletions homeassistant/components/unifi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,18 @@
CONF_VERIFY_SSL,
)
from homeassistant.core import callback
import homeassistant.helpers.config_validation as cv

from .const import (
CONF_ALLOW_BANDWIDTH_SENSORS,
CONF_CONTROLLER,
CONF_DETECTION_TIME,
CONF_SITE_ID,
CONF_SSID_FILTER,
CONF_TRACK_CLIENTS,
CONF_TRACK_DEVICES,
CONF_TRACK_WIRED_CLIENTS,
CONTROLLER_ID,
DEFAULT_ALLOW_BANDWIDTH_SENSORS,
DEFAULT_DETECTION_TIME,
DEFAULT_TRACK_CLIENTS,
DEFAULT_TRACK_DEVICES,
DEFAULT_TRACK_WIRED_CLIENTS,
DOMAIN,
LOGGER,
)
Expand Down Expand Up @@ -185,33 +182,30 @@ async def async_step_device_tracker(self, user_input=None):
self.options.update(user_input)
return await self.async_step_statistics_sensors()

controller = get_controller_from_config_entry(self.hass, self.config_entry)

ssid_filter = {wlan: wlan for wlan in controller.api.wlans}

return self.async_show_form(
step_id="device_tracker",
data_schema=vol.Schema(
{
vol.Optional(
CONF_TRACK_CLIENTS,
default=self.config_entry.options.get(
CONF_TRACK_CLIENTS, DEFAULT_TRACK_CLIENTS
),
CONF_TRACK_CLIENTS, default=controller.option_track_clients,
): bool,
vol.Optional(
CONF_TRACK_WIRED_CLIENTS,
default=self.config_entry.options.get(
CONF_TRACK_WIRED_CLIENTS, DEFAULT_TRACK_WIRED_CLIENTS
),
default=controller.option_track_wired_clients,
): bool,
vol.Optional(
CONF_TRACK_DEVICES,
default=self.config_entry.options.get(
CONF_TRACK_DEVICES, DEFAULT_TRACK_DEVICES
),
CONF_TRACK_DEVICES, default=controller.option_track_devices,
): bool,
vol.Optional(
CONF_SSID_FILTER, default=controller.option_ssid_filter
): cv.multi_select(ssid_filter),
vol.Optional(
CONF_DETECTION_TIME,
default=self.config_entry.options.get(
CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME
),
default=int(controller.option_detection_time.total_seconds()),
): int,
}
),
Expand All @@ -223,16 +217,15 @@ async def async_step_statistics_sensors(self, user_input=None):
self.options.update(user_input)
return await self._update_options()

controller = get_controller_from_config_entry(self.hass, self.config_entry)

return self.async_show_form(
step_id="statistics_sensors",
data_schema=vol.Schema(
{
vol.Optional(
CONF_ALLOW_BANDWIDTH_SENSORS,
default=self.config_entry.options.get(
CONF_ALLOW_BANDWIDTH_SENSORS,
DEFAULT_ALLOW_BANDWIDTH_SENSORS,
),
default=controller.option_allow_bandwidth_sensors,
): bool
}
),
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/unifi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/unifi",
"requirements": [
"aiounifi==12"
"aiounifi==13"
],
"dependencies": [],
"codeowners": [
Expand Down
11 changes: 8 additions & 3 deletions homeassistant/components/unifi/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@
"device_tracker": {
"data": {
"detection_time": "Time in seconds from last seen until considered away",
"ssid_filter": "Select SSIDs to track wireless clients on",
"track_clients": "Track network clients",
"track_devices": "Track network devices (Ubiquiti devices)",
"track_wired_clients": "Include wired network clients"
}
},
"description": "Configure device tracking",
"title": "UniFi options"
},
"statistics_sensors": {
"data": {
"allow_bandwidth_sensors": "Create bandwidth usage sensors for network clients"
}
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
},
"description": "Configure statistics sensors",
"title": "UniFi options"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ aiopylgtv==0.3.3
aioswitcher==2019.4.26

# homeassistant.components.unifi
aiounifi==12
aiounifi==13

# homeassistant.components.wwlln
aiowwlln==2.0.2
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ aiopylgtv==0.3.3
aioswitcher==2019.4.26

# homeassistant.components.unifi
aiounifi==12
aiounifi==13

# homeassistant.components.wwlln
aiowwlln==2.0.2
Expand Down
32 changes: 20 additions & 12 deletions tests/components/unifi/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import aiounifi
from asynctest import patch

from homeassistant import data_entry_flow
from homeassistant.components import unifi
from homeassistant.components.unifi import config_flow
from homeassistant.components.unifi.const import CONF_CONTROLLER, CONF_SITE_ID
Expand All @@ -13,8 +14,12 @@
CONF_VERIFY_SSL,
)

from .test_controller import setup_unifi_integration

from tests.common import MockConfigEntry

WLANS = [{"name": "SSID 1"}, {"name": "SSID 2"}]


async def test_flow_works(hass, aioclient_mock, mock_discovery):
"""Test config flow."""
Expand Down Expand Up @@ -236,36 +241,39 @@ async def test_flow_fails_unknown_problem(hass, aioclient_mock):

async def test_option_flow(hass):
"""Test config flow options."""
entry = MockConfigEntry(domain=config_flow.DOMAIN, data={}, options=None)
hass.config_entries._entries.append(entry)
controller = await setup_unifi_integration(hass, wlans_response=WLANS)

flow = await hass.config_entries.options.async_create_flow(
entry.entry_id, context={"source": "test"}, data=None
result = await hass.config_entries.options.async_init(
controller.config_entry.entry_id
)

result = await flow.async_step_init()
assert result["type"] == "form"
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "device_tracker"

result = await flow.async_step_device_tracker(
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
config_flow.CONF_TRACK_CLIENTS: False,
config_flow.CONF_TRACK_WIRED_CLIENTS: False,
config_flow.CONF_TRACK_DEVICES: False,
config_flow.CONF_SSID_FILTER: ["SSID 1"],
config_flow.CONF_DETECTION_TIME: 100,
}
},
)
assert result["type"] == "form"

assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "statistics_sensors"

result = await flow.async_step_statistics_sensors(
user_input={config_flow.CONF_ALLOW_BANDWIDTH_SENSORS: True}
result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={config_flow.CONF_ALLOW_BANDWIDTH_SENSORS: True}
)
assert result["type"] == "create_entry"

assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"] == {
config_flow.CONF_TRACK_CLIENTS: False,
config_flow.CONF_TRACK_WIRED_CLIENTS: False,
config_flow.CONF_TRACK_DEVICES: False,
config_flow.CONF_DETECTION_TIME: 100,
config_flow.CONF_SSID_FILTER: ["SSID 1"],
config_flow.CONF_ALLOW_BANDWIDTH_SENSORS: True,
}
8 changes: 8 additions & 0 deletions tests/components/unifi/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ async def setup_unifi_integration(
clients_response=None,
devices_response=None,
clients_all_response=None,
wlans_response=None,
known_wireless_clients=None,
controllers=None,
):
Expand Down Expand Up @@ -98,6 +99,10 @@ async def setup_unifi_integration(
if clients_all_response:
mock_client_all_responses.append(clients_all_response)

mock_wlans_responses = deque()
if wlans_response:
mock_wlans_responses.append(wlans_response)

mock_requests = []

async def mock_request(self, method, path, json=None):
Expand All @@ -109,6 +114,8 @@ async def mock_request(self, method, path, json=None):
return mock_device_responses.popleft()
if path == "s/{site}/rest/user" and mock_client_all_responses:
return mock_client_all_responses.popleft()
if path == "s/{site}/rest/wlanconf" and mock_wlans_responses:
return mock_wlans_responses.popleft()
return {}

# "aiounifi.Controller.start_websocket", return_value=True
Expand All @@ -128,6 +135,7 @@ async def mock_request(self, method, path, json=None):
controller.mock_client_responses = mock_client_responses
controller.mock_device_responses = mock_device_responses
controller.mock_client_all_responses = mock_client_all_responses
controller.mock_wlans_responses = mock_wlans_responses
controller.mock_requests = mock_requests

return controller
Expand Down
4 changes: 2 additions & 2 deletions tests/components/unifi/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_no_clients(hass):
hass, options={unifi.const.CONF_ALLOW_BANDWIDTH_SENSORS: True},
)

assert len(controller.mock_requests) == 3
assert len(controller.mock_requests) == 4
assert len(hass.states.async_all()) == 1


Expand All @@ -70,7 +70,7 @@ async def test_sensors(hass):
clients_response=CLIENTS,
)

assert len(controller.mock_requests) == 3
assert len(controller.mock_requests) == 4
assert len(hass.states.async_all()) == 5

wired_client_rx = hass.states.get("sensor.wired_client_name_rx")
Expand Down
Loading