Skip to content

Instantly share code, notes, and snippets.

@balloob
Created August 15, 2019 20:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balloob/f0c433d10d4f0f003cb2cccb08d9901f to your computer and use it in GitHub Desktop.
Save balloob/f0c433d10d4f0f003cb2cccb08d9901f to your computer and use it in GitHub Desktop.
Example options flow
diff --git a/homeassistant/components/unifi/config_flow.py b/homeassistant/components/unifi/config_flow.py
index e5a8965df..06751ed6e 100644
--- a/homeassistant/components/unifi/config_flow.py
+++ b/homeassistant/components/unifi/config_flow.py
@@ -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,
@@ -26,6 +27,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 +149,28 @@ 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 options flow."""
+ self.config_entry = config_entry
+
+ async def async_step_init(self, user_input=None):
+ """Manage the options."""
+ if user_input is not None:
+ return self.async_create_entry(title="", data=user_input)
+
+ return self.async_show_form(
+ step_id="init",
+ data_schema=vol.Schema(
+ {
+ vol.Required(
+ "show_things",
+ default=self.config_entry.options.get("show_things"),
+ ): bool
+ }
+ ),
+ )
diff --git a/homeassistant/components/unifi/strings.json b/homeassistant/components/unifi/strings.json
index 938ac058d..7f0800e66 100644
--- a/homeassistant/components/unifi/strings.json
+++ b/homeassistant/components/unifi/strings.json
@@ -1,26 +1,35 @@
{
- "config": {
- "title": "UniFi Controller",
- "step": {
- "user": {
- "title": "Set up UniFi Controller",
- "data": {
- "host": "Host",
- "username": "User name",
- "password": "Password",
- "port": "Port",
- "site": "Site ID",
- "verify_ssl": "Controller using proper certificate"
- }
- }
- },
- "error": {
- "faulty_credentials": "Bad user credentials",
- "service_unavailable": "No service available"
- },
- "abort": {
- "already_configured": "Controller site is already configured",
- "user_privilege": "User needs to be administrator"
+ "config": {
+ "title": "UniFi Controller",
+ "step": {
+ "user": {
+ "title": "Set up UniFi Controller",
+ "data": {
+ "host": "Host",
+ "username": "User name",
+ "password": "Password",
+ "port": "Port",
+ "site": "Site ID",
+ "verify_ssl": "Controller using proper certificate"
}
+ }
+ },
+ "error": {
+ "faulty_credentials": "Bad user credentials",
+ "service_unavailable": "No service available"
+ },
+ "abort": {
+ "already_configured": "Controller site is already configured",
+ "user_privilege": "User needs to be administrator"
}
-}
\ No newline at end of file
+ },
+ "options": {
+ "step": {
+ "init": {
+ "data": {
+ "show_things": "Show Things"
+ }
+ }
+ }
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment