Add config option to set timeout for wiffi devices (#35694)

* add config option to set timeout for wiffi devices

Wiffi devices allow to configure the update period (=
full_loop_minutes). The integration shall respect the configured update
period and therefore need a configuration for the timeout, too.

* Move timeout from config flow to option flow

* add test for option flow
This commit is contained in:
Steffen Zimmermann 2020-05-17 10:31:28 +02:00 committed by GitHub
parent d02bb70f0c
commit 51eebb3906
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 19 deletions

View file

@ -8,10 +8,14 @@ import voluptuous as vol
from wiffi import WiffiTcpServer
from homeassistant import config_entries
from homeassistant.const import CONF_PORT
from homeassistant.const import CONF_PORT, CONF_TIMEOUT
from homeassistant.core import callback
from .const import DEFAULT_PORT, DOMAIN # pylint: disable=unused-import
from .const import ( # pylint: disable=unused-import
DEFAULT_PORT,
DEFAULT_TIMEOUT,
DOMAIN,
)
class WiffiFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
@ -20,6 +24,12 @@ class WiffiFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_PUSH
@staticmethod
@callback
def async_get_options_flow(config_entry):
"""Create Wiffi server setup option flow."""
return OptionsFlowHandler(config_entry)
async def async_step_user(self, user_input=None):
"""Handle the start of the config flow.
@ -55,3 +65,30 @@ class WiffiFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_show_form(
step_id="user", data_schema=vol.Schema(data_schema), errors=errors or {}
)
class OptionsFlowHandler(config_entries.OptionsFlow):
"""Wiffi server setup option flow."""
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.Optional(
CONF_TIMEOUT,
default=self.config_entry.options.get(
CONF_TIMEOUT, DEFAULT_TIMEOUT
),
): int,
}
),
)