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
38 changes: 37 additions & 1 deletion homeassistant/components/unifi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,43 @@ async def async_step_init(self, user_input=None):
"""Manage the UniFi options."""
self.controller = self.hass.data[UNIFI_DOMAIN][self.config_entry.entry_id]
self.options[CONF_BLOCK_CLIENT] = self.controller.option_block_clients
return await self.async_step_device_tracker()

if self.show_advanced_options:
return await self.async_step_device_tracker()

return await self.async_step_simple_options()

async def async_step_simple_options(self, user_input=None):
"""For simple Jack."""
if user_input is not None:
self.options.update(user_input)
return await self._update_options()

clients_to_block = {}

for client in self.controller.api.clients.values():
clients_to_block[
client.mac
] = f"{client.name or client.hostname} ({client.mac})"

return self.async_show_form(
step_id="simple_options",
data_schema=vol.Schema(
{
vol.Optional(
CONF_TRACK_CLIENTS,
default=self.controller.option_track_clients,
): bool,
vol.Optional(
CONF_TRACK_DEVICES,
default=self.controller.option_track_devices,
): bool,
vol.Optional(
CONF_BLOCK_CLIENT, default=self.options[CONF_BLOCK_CLIENT]
): cv.multi_select(clients_to_block),
}
),
)

async def async_step_device_tracker(self, user_input=None):
"""Manage the device tracker options."""
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/unifi/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"description": "Configure client controls\n\nCreate switches for serial numbers you want to control network access for.",
"title": "UniFi options 2/3"
},
"simple_options": {
"data": {
"track_clients": "[%key:component::unifi::options::step::device_tracker::data::track_clients%]",
"track_devices": "[%key:component::unifi::options::step::device_tracker::data::track_devices%]",
"block_client": "[%key:component::unifi::options::step::client_control::data::block_client%]"
},
"description": "Configure UniFi integration"
},
"statistics_sensors": {
"data": {
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/unifi/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
"description": "Configure device tracking",
"title": "UniFi options 1/3"
},
"simple_options": {
"data": {
"track_clients": "[%key:component::unifi::options::step::device_tracker::data::track_clients%]",
"track_devices": "[%key:component::unifi::options::step::device_tracker::data::track_devices%]",
"block_client": "[%key:component::unifi::options::step::client_control::data::block_client%]"
},
"description": "Configure UniFi integration"
},
"statistics_sensors": {
"data": {
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
Expand Down
36 changes: 33 additions & 3 deletions tests/components/unifi/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,14 @@ async def test_flow_fails_unknown_problem(hass, aioclient_mock):
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT


async def test_option_flow(hass):
"""Test config flow options."""
async def test_advanced_option_flow(hass):
"""Test advanced config flow options."""
controller = await setup_unifi_integration(
hass, clients_response=CLIENTS, wlans_response=WLANS
)

result = await hass.config_entries.options.async_init(
controller.config_entry.entry_id
controller.config_entry.entry_id, context={"show_advanced_options": True}
)

assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
Expand Down Expand Up @@ -315,3 +315,33 @@ async def test_option_flow(hass):
CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]],
CONF_ALLOW_BANDWIDTH_SENSORS: True,
}


async def test_simple_option_flow(hass):
"""Test simple config flow options."""
controller = await setup_unifi_integration(
hass, clients_response=CLIENTS, wlans_response=WLANS
)

result = await hass.config_entries.options.async_init(
controller.config_entry.entry_id, context={"show_advanced_options": False}
)

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

result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
CONF_TRACK_CLIENTS: False,
CONF_TRACK_DEVICES: False,
CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]],
},
)

assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"] == {
CONF_TRACK_CLIENTS: False,
CONF_TRACK_DEVICES: False,
CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]],
}