mirror of
https://github.com/home-assistant/core
synced 2024-10-07 10:13:38 +02:00
UniFi - Add simple options flow (#34990)
This commit is contained in:
parent
03bb2a68b3
commit
72e7beeb76
@ -175,7 +175,43 @@ class UnifiOptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
"""Manage the UniFi options."""
|
"""Manage the UniFi options."""
|
||||||
self.controller = self.hass.data[UNIFI_DOMAIN][self.config_entry.entry_id]
|
self.controller = self.hass.data[UNIFI_DOMAIN][self.config_entry.entry_id]
|
||||||
self.options[CONF_BLOCK_CLIENT] = self.controller.option_block_clients
|
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):
|
async def async_step_device_tracker(self, user_input=None):
|
||||||
"""Manage the device tracker options."""
|
"""Manage the device tracker options."""
|
||||||
|
@ -46,6 +46,14 @@
|
|||||||
"description": "Configure client controls\n\nCreate switches for serial numbers you want to control network access for.",
|
"description": "Configure client controls\n\nCreate switches for serial numbers you want to control network access for.",
|
||||||
"title": "UniFi options 2/3"
|
"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": {
|
"statistics_sensors": {
|
||||||
"data": {
|
"data": {
|
||||||
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
|
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
|
||||||
|
@ -46,6 +46,14 @@
|
|||||||
"description": "Configure device tracking",
|
"description": "Configure device tracking",
|
||||||
"title": "UniFi options 1/3"
|
"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": {
|
"statistics_sensors": {
|
||||||
"data": {
|
"data": {
|
||||||
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
|
"allow_bandwidth_sensors": "Bandwidth usage sensors for network clients"
|
||||||
|
@ -264,14 +264,14 @@ async def test_flow_fails_unknown_problem(hass, aioclient_mock):
|
|||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||||
|
|
||||||
|
|
||||||
async def test_option_flow(hass):
|
async def test_advanced_option_flow(hass):
|
||||||
"""Test config flow options."""
|
"""Test advanced config flow options."""
|
||||||
controller = await setup_unifi_integration(
|
controller = await setup_unifi_integration(
|
||||||
hass, clients_response=CLIENTS, wlans_response=WLANS
|
hass, clients_response=CLIENTS, wlans_response=WLANS
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await hass.config_entries.options.async_init(
|
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
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
@ -315,3 +315,33 @@ async def test_option_flow(hass):
|
|||||||
CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]],
|
CONF_BLOCK_CLIENT: [CLIENTS[0]["mac"]],
|
||||||
CONF_ALLOW_BANDWIDTH_SENSORS: True,
|
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"]],
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user