UniFi config entry options (#26113)

Introduce config entry options for Unifi integration
Allow configuration.yaml options to be imported to new options
This commit is contained in:
Robert Svensson 2019-08-21 22:22:42 +02:00 committed by GitHub
parent 7ab36e0381
commit 588eac82c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 250 additions and 75 deletions

View file

@ -2,6 +2,7 @@
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.core import callback
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
@ -10,7 +11,20 @@ from homeassistant.const import (
CONF_VERIFY_SSL,
)
from .const import CONF_CONTROLLER, CONF_SITE_ID, DOMAIN, LOGGER
from .const import (
CONF_CONTROLLER,
CONF_TRACK_CLIENTS,
CONF_TRACK_DEVICES,
CONF_TRACK_WIRED_CLIENTS,
CONF_DETECTION_TIME,
CONF_SITE_ID,
DEFAULT_TRACK_CLIENTS,
DEFAULT_TRACK_DEVICES,
DEFAULT_TRACK_WIRED_CLIENTS,
DEFAULT_DETECTION_TIME,
DOMAIN,
LOGGER,
)
from .controller import get_controller
from .errors import AlreadyConfigured, AuthenticationRequired, CannotConnect
@ -26,6 +40,12 @@ class UnifiFlowHandler(config_entries.ConfigFlow):
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Get the options flow for this handler."""
return UnifiOptionsFlowHandler(config_entry)
def __init__(self):
"""Initialize the UniFi flow."""
self.config = None
@ -142,3 +162,52 @@ class UnifiFlowHandler(config_entries.ConfigFlow):
self.desc = import_config[CONF_SITE_ID]
return await self.async_step_user(user_input=config)
class UnifiOptionsFlowHandler(config_entries.OptionsFlow):
"""Handle Unifi options."""
def __init__(self, config_entry):
"""Initialize UniFi options flow."""
self.config_entry = config_entry
async def async_step_init(self, user_input=None):
"""Manage the UniFi options."""
return await self.async_step_device_tracker()
async def async_step_device_tracker(self, user_input=None):
"""Manage the device tracker options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
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
),
): bool,
vol.Optional(
CONF_TRACK_WIRED_CLIENTS,
default=self.config_entry.options.get(
CONF_TRACK_WIRED_CLIENTS, DEFAULT_TRACK_WIRED_CLIENTS
),
): bool,
vol.Optional(
CONF_TRACK_DEVICES,
default=self.config_entry.options.get(
CONF_TRACK_DEVICES, DEFAULT_TRACK_DEVICES
),
): bool,
vol.Optional(
CONF_DETECTION_TIME,
default=self.config_entry.options.get(
CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME
),
): int,
}
),
)