Implemented multi page config to accommodate more options #68

This commit is contained in:
tomaae 2020-12-10 06:10:00 +01:00
parent 5aa6652301
commit bbd29aad48
2 changed files with 42 additions and 26 deletions

View file

@ -149,16 +149,16 @@ class MikrotikControllerOptionsFlowHandler(OptionsFlow):
async def async_step_init(self, user_input=None): async def async_step_init(self, user_input=None):
"""Manage the options.""" """Manage the options."""
return await self.async_step_device_tracker(user_input) return await self.async_step_basic_options(user_input)
async def async_step_device_tracker(self, user_input=None): async def async_step_basic_options(self, user_input=None):
"""Manage the device tracker options.""" """Manage the basic options options."""
if user_input is not None: if user_input is not None:
self.options.update(user_input) self.options.update(user_input)
return self.async_create_entry(title="", data=self.options) return await self.async_step_device_tracker()
return self.async_show_form( return self.async_show_form(
step_id="device_tracker", step_id="basic_options",
data_schema=vol.Schema( data_schema=vol.Schema(
{ {
vol.Optional( vol.Optional(
@ -179,6 +179,20 @@ class MikrotikControllerOptionsFlowHandler(OptionsFlow):
CONF_TRACK_IFACE_CLIENTS, DEFAULT_TRACK_IFACE_CLIENTS CONF_TRACK_IFACE_CLIENTS, DEFAULT_TRACK_IFACE_CLIENTS
), ),
): bool, ): bool,
}
),
)
async def async_step_device_tracker(self, user_input=None):
"""Manage the device tracker options."""
if user_input is not None:
self.options.update(user_input)
return self.async_create_entry(title="", data=self.options)
return self.async_show_form(
step_id="device_tracker",
data_schema=vol.Schema(
{
vol.Optional( vol.Optional(
CONF_TRACK_HOSTS, CONF_TRACK_HOSTS,
default=self.config_entry.options.get( default=self.config_entry.options.get(

View file

@ -1,41 +1,43 @@
{ {
"config": { "config": {
"title": "Mikrotik Router", "error": {
"cannot_connect": "Cannot connect to Mikrotik.",
"connection_timeout": "Mikrotik connection timeout.",
"name_exists": "Name already exists.",
"ssl_handshake_failure": "SSL handshake failure",
"wrong_login": "Invalid user name or password."
},
"step": { "step": {
"user": { "user": {
"title": "Mikrotik Router",
"description": "Set up Mikrotik Router integration.",
"data": { "data": {
"name": "Name of the integration",
"host": "Host", "host": "Host",
"port": "Port", "name": "Name of the integration",
"username": "Username",
"password": "Password", "password": "Password",
"ssl": "Use SSL" "port": "Port",
} "ssl": "Use SSL",
} "username": "Username"
}, },
"error": { "description": "Set up Mikrotik Router integration.",
"name_exists": "Name already exists.", "title": "Mikrotik Router"
"cannot_connect": "Cannot connect to Mikrotik.", }
"ssl_handshake_failure": "SSL handshake failure",
"connection_timeout": "Mikrotik connection timeout.",
"wrong_login": "Invalid user name or password."
} }
}, },
"options": { "options": {
"step": { "step": {
"init": { "basic_options": {
"data": {}
},
"device_tracker": {
"data": { "data": {
"scan_interval": "Scan interval (requires HA restart)", "scan_interval": "Scan interval (requires HA restart)",
"track_iface_clients": "Show client MAC and IP on interfaces", "track_iface_clients": "Show client MAC and IP on interfaces",
"unit_of_measurement": "Unit of measurement", "unit_of_measurement": "Unit of measurement"
},
"title": "Basic options"
},
"device_tracker": {
"data": {
"track_network_hosts": "Track network devices", "track_network_hosts": "Track network devices",
"track_network_hosts_timeout": "Track network devices timeout (seconds)" "track_network_hosts_timeout": "Track network devices timeout (seconds)"
} },
"title": "Device tracking options"
} }
} }
} }