diff --git a/homeassistant/components/vesync/config_flow.py b/homeassistant/components/vesync/config_flow.py index 6115cb9ee76664..18fb0c727c7e31 100644 --- a/homeassistant/components/vesync/config_flow.py +++ b/homeassistant/components/vesync/config_flow.py @@ -5,12 +5,17 @@ from pyvesync import VeSync import voluptuous as vol -from homeassistant.config_entries import ConfigFlow, ConfigFlowResult -from homeassistant.const import CONF_PASSWORD, CONF_USERNAME +from homeassistant.config_entries import ( + ConfigEntry, + ConfigFlow, + ConfigFlowResult, + OptionsFlow, +) +from homeassistant.const import CONF_PASSWORD, CONF_SCAN_INTERVAL, CONF_USERNAME from homeassistant.core import callback import homeassistant.helpers.config_validation as cv -from .const import DOMAIN +from .const import DEFAULT_SCAN_INTERVAL, DOMAIN DATA_SCHEMA = vol.Schema( { @@ -20,11 +25,45 @@ ) +class VesyncOptionFlowHandler(OptionsFlow): + """Handle an option flow for Vesync.""" + + def __init__(self, config_entry: ConfigEntry) -> None: + """Initialize option flow instance.""" + self.config_entry = config_entry + + async def async_step_init( + self, user_input: dict[str, Any] | None = None + ) -> ConfigFlowResult: + """Manage the vesync options.""" + if user_input is not None: + return self.async_create_entry(title="", data=user_input) + + options = { + vol.Optional( + CONF_SCAN_INTERVAL, + default=self.config_entry.options.get( + CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL + ), + ): int, + } + + return self.async_show_form(step_id="init", data_schema=vol.Schema(options)) + + class VeSyncFlowHandler(ConfigFlow, domain=DOMAIN): """Handle a config flow.""" VERSION = 1 + @staticmethod + @callback + def async_get_options_flow( + config_entry: ConfigEntry, + ) -> VesyncOptionFlowHandler: + """Get the options flow for this handler.""" + return VesyncOptionFlowHandler(config_entry) + @callback def _show_form(self, errors: dict[str, str] | None = None) -> ConfigFlowResult: """Show form to the user.""" diff --git a/homeassistant/components/vesync/const.py b/homeassistant/components/vesync/const.py index 50dce95e42a40c..0f62b01bc672d1 100644 --- a/homeassistant/components/vesync/const.py +++ b/homeassistant/components/vesync/const.py @@ -67,3 +67,5 @@ "LAP-EL551S-WEU": "EverestAir", # Alt ID Model EverestAir "LAP-EL551S-WUS": "EverestAir", # Alt ID Model EverestAir } + +DEFAULT_SCAN_INTERVAL: int = 15 diff --git a/homeassistant/components/vesync/strings.json b/homeassistant/components/vesync/strings.json index 5ff0aa58722f71..961ed0fa62da01 100644 --- a/homeassistant/components/vesync/strings.json +++ b/homeassistant/components/vesync/strings.json @@ -16,6 +16,15 @@ "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" } }, + "options": { + "step": { + "init": { + "data": { + "scan_interval": "Update interval" + } + } + } + }, "entity": { "sensor": { "filter_life": {