UniFi - Add simple options flow (#34990)

This commit is contained in:
Robert Svensson authored and GitHub committed 2020-04-30 22:33:22 -07:00
1 parent 03bb2a68b3
commit 72e7beeb76
4 files changed
+86 -4

No files matched your search

+37 -1
View File
@@ -175,7 +175,43 @@ class UnifiOptionsFlowHandler(config_entries.OptionsFlow):
"""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."""
@@ -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"
@@ -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"