mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Remove usage of options property in OptionsFlow (part 1) (#129895)
* Remove usage of options property in OptionsFlow * Improve
This commit is contained in:
parent
611a952232
commit
c54ed53a81
@ -212,6 +212,6 @@ class HomeassistantAnalyticsOptionsFlowHandler(OptionsFlow):
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
self.options,
|
self.config_entry.options,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -235,7 +235,7 @@ class OptionsFlowHandler(OptionsFlow):
|
|||||||
SelectOptionDict(value=k, label=v) for k, v in apps_list.items()
|
SelectOptionDict(value=k, label=v) for k, v in apps_list.items()
|
||||||
]
|
]
|
||||||
rules = [RULES_NEW_ID, *self._state_det_rules]
|
rules = [RULES_NEW_ID, *self._state_det_rules]
|
||||||
options = self.options
|
options = self.config_entry.options
|
||||||
|
|
||||||
data_schema = vol.Schema(
|
data_schema = vol.Schema(
|
||||||
{
|
{
|
||||||
|
@ -168,7 +168,7 @@ class ElevenLabsOptionsFlow(OptionsFlow):
|
|||||||
vol.Required(CONF_CONFIGURE_VOICE, default=False): bool,
|
vol.Required(CONF_CONFIGURE_VOICE, default=False): bool,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
self.options,
|
self.config_entry.options,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_voice_settings(
|
async def async_step_voice_settings(
|
||||||
|
@ -163,7 +163,9 @@ class FeedReaderOptionsFlowHandler(OptionsFlow):
|
|||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_MAX_ENTRIES,
|
CONF_MAX_ENTRIES,
|
||||||
default=self.options.get(CONF_MAX_ENTRIES, DEFAULT_MAX_ENTRIES),
|
default=self.config_entry.options.get(
|
||||||
|
CONF_MAX_ENTRIES, DEFAULT_MAX_ENTRIES
|
||||||
|
),
|
||||||
): cv.positive_int,
|
): cv.positive_int,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -405,19 +405,18 @@ class FritzBoxToolsOptionsFlowHandler(OptionsFlow):
|
|||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="", data=user_input)
|
return self.async_create_entry(title="", data=user_input)
|
||||||
|
|
||||||
|
options = self.config_entry.options
|
||||||
data_schema = vol.Schema(
|
data_schema = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_CONSIDER_HOME,
|
CONF_CONSIDER_HOME,
|
||||||
default=self.options.get(
|
default=options.get(
|
||||||
CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
|
CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
|
||||||
),
|
),
|
||||||
): vol.All(vol.Coerce(int), vol.Clamp(min=0, max=900)),
|
): vol.All(vol.Coerce(int), vol.Clamp(min=0, max=900)),
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_OLD_DISCOVERY,
|
CONF_OLD_DISCOVERY,
|
||||||
default=self.options.get(
|
default=options.get(CONF_OLD_DISCOVERY, DEFAULT_CONF_OLD_DISCOVERY),
|
||||||
CONF_OLD_DISCOVERY, DEFAULT_CONF_OLD_DISCOVERY
|
|
||||||
),
|
|
||||||
): bool,
|
): bool,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -359,7 +359,7 @@ class LmOptionsFlowHandler(OptionsFlow):
|
|||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_USE_BLUETOOTH,
|
CONF_USE_BLUETOOTH,
|
||||||
default=self.options.get(CONF_USE_BLUETOOTH, True),
|
default=self.config_entry.options.get(CONF_USE_BLUETOOTH, True),
|
||||||
): cv.boolean,
|
): cv.boolean,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,6 @@ from homeassistant.config_entries import (
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_RADIUS,
|
CONF_RADIUS,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
@ -112,10 +111,7 @@ class OpenSkyOptionsFlowHandler(OptionsFlow):
|
|||||||
except OpenSkyUnauthenticatedError:
|
except OpenSkyUnauthenticatedError:
|
||||||
errors["base"] = "invalid_auth"
|
errors["base"] = "invalid_auth"
|
||||||
if not errors:
|
if not errors:
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(data=user_input)
|
||||||
title=self.options.get(CONF_NAME, "OpenSky"),
|
|
||||||
data=user_input,
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
@ -130,6 +126,6 @@ class OpenSkyOptionsFlowHandler(OptionsFlow):
|
|||||||
vol.Optional(CONF_CONTRIBUTING_USER, default=False): bool,
|
vol.Optional(CONF_CONTRIBUTING_USER, default=False): bool,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
user_input or self.options,
|
user_input or self.config_entry.options,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -199,7 +199,7 @@ class PVPCOptionsFlowHandler(OptionsFlow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fill options with entry data
|
# Fill options with entry data
|
||||||
api_token = self.options.get(
|
api_token = self.config_entry.options.get(
|
||||||
CONF_API_TOKEN, self.config_entry.data.get(CONF_API_TOKEN)
|
CONF_API_TOKEN, self.config_entry.data.get(CONF_API_TOKEN)
|
||||||
)
|
)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
@ -229,13 +229,11 @@ class PVPCOptionsFlowHandler(OptionsFlow):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Fill options with entry data
|
# Fill options with entry data
|
||||||
power = self.options.get(ATTR_POWER, self.config_entry.data[ATTR_POWER])
|
options = self.config_entry.options
|
||||||
power_valley = self.options.get(
|
data = self.config_entry.data
|
||||||
ATTR_POWER_P3, self.config_entry.data[ATTR_POWER_P3]
|
power = options.get(ATTR_POWER, data[ATTR_POWER])
|
||||||
)
|
power_valley = options.get(ATTR_POWER_P3, data[ATTR_POWER_P3])
|
||||||
api_token = self.options.get(
|
api_token = options.get(CONF_API_TOKEN, data.get(CONF_API_TOKEN))
|
||||||
CONF_API_TOKEN, self.config_entry.data.get(CONF_API_TOKEN)
|
|
||||||
)
|
|
||||||
use_api_token = api_token is not None
|
use_api_token = api_token is not None
|
||||||
schema = vol.Schema(
|
schema = vol.Schema(
|
||||||
{
|
{
|
||||||
|
@ -186,7 +186,7 @@ class RokuOptionsFlowHandler(OptionsFlow):
|
|||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_PLAY_MEDIA_APP_ID,
|
CONF_PLAY_MEDIA_APP_ID,
|
||||||
default=self.options.get(
|
default=self.config_entry.options.get(
|
||||||
CONF_PLAY_MEDIA_APP_ID, DEFAULT_PLAY_MEDIA_APP_ID
|
CONF_PLAY_MEDIA_APP_ID, DEFAULT_PLAY_MEDIA_APP_ID
|
||||||
),
|
),
|
||||||
): str,
|
): str,
|
||||||
|
@ -310,17 +310,18 @@ class RoombaOptionsFlowHandler(OptionsFlow):
|
|||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
return self.async_create_entry(title="", data=user_input)
|
return self.async_create_entry(title="", data=user_input)
|
||||||
|
|
||||||
|
options = self.config_entry.options
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_CONTINUOUS,
|
CONF_CONTINUOUS,
|
||||||
default=self.options.get(CONF_CONTINUOUS, DEFAULT_CONTINUOUS),
|
default=options.get(CONF_CONTINUOUS, DEFAULT_CONTINUOUS),
|
||||||
): bool,
|
): bool,
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_DELAY,
|
CONF_DELAY,
|
||||||
default=self.options.get(CONF_DELAY, DEFAULT_DELAY),
|
default=options.get(CONF_DELAY, DEFAULT_DELAY),
|
||||||
): int,
|
): int,
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
@ -223,7 +223,7 @@ class SQLOptionsFlowHandler(OptionsFlow):
|
|||||||
db_url = user_input.get(CONF_DB_URL)
|
db_url = user_input.get(CONF_DB_URL)
|
||||||
query = user_input[CONF_QUERY]
|
query = user_input[CONF_QUERY]
|
||||||
column = user_input[CONF_COLUMN_NAME]
|
column = user_input[CONF_COLUMN_NAME]
|
||||||
name = self.options.get(CONF_NAME, self.config_entry.title)
|
name = self.config_entry.options.get(CONF_NAME, self.config_entry.title)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
query = validate_sql_select(query)
|
query = validate_sql_select(query)
|
||||||
@ -275,7 +275,7 @@ class SQLOptionsFlowHandler(OptionsFlow):
|
|||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
OPTIONS_SCHEMA, user_input or self.options
|
OPTIONS_SCHEMA, user_input or self.config_entry.options
|
||||||
),
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
description_placeholders=description_placeholders,
|
description_placeholders=description_placeholders,
|
||||||
|
@ -247,7 +247,7 @@ class TVTrainOptionsFlowHandler(OptionsFlow):
|
|||||||
step_id="init",
|
step_id="init",
|
||||||
data_schema=self.add_suggested_values_to_schema(
|
data_schema=self.add_suggested_values_to_schema(
|
||||||
vol.Schema(OPTION_SCHEMA),
|
vol.Schema(OPTION_SCHEMA),
|
||||||
user_input or self.options,
|
user_input or self.config_entry.options,
|
||||||
),
|
),
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
@ -314,7 +314,7 @@ class UpnpOptionsFlowHandler(OptionsFlow):
|
|||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONFIG_ENTRY_FORCE_POLL,
|
CONFIG_ENTRY_FORCE_POLL,
|
||||||
default=self.options.get(
|
default=self.config_entry.options.get(
|
||||||
CONFIG_ENTRY_FORCE_POLL, DEFAULT_CONFIG_ENTRY_FORCE_POLL
|
CONFIG_ENTRY_FORCE_POLL, DEFAULT_CONFIG_ENTRY_FORCE_POLL
|
||||||
),
|
),
|
||||||
): bool,
|
): bool,
|
||||||
|
@ -159,7 +159,7 @@ class VodafoneStationOptionsFlowHandler(OptionsFlow):
|
|||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_CONSIDER_HOME,
|
CONF_CONSIDER_HOME,
|
||||||
default=self.options.get(
|
default=self.config_entry.options.get(
|
||||||
CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
|
CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
|
||||||
),
|
),
|
||||||
): vol.All(vol.Coerce(int), vol.Clamp(min=0, max=900))
|
): vol.All(vol.Coerce(int), vol.Clamp(min=0, max=900))
|
||||||
|
@ -135,7 +135,7 @@ class WLEDOptionsFlowHandler(OptionsFlow):
|
|||||||
{
|
{
|
||||||
vol.Optional(
|
vol.Optional(
|
||||||
CONF_KEEP_MAIN_LIGHT,
|
CONF_KEEP_MAIN_LIGHT,
|
||||||
default=self.options.get(
|
default=self.config_entry.options.get(
|
||||||
CONF_KEEP_MAIN_LIGHT, DEFAULT_KEEP_MAIN_LIGHT
|
CONF_KEEP_MAIN_LIGHT, DEFAULT_KEEP_MAIN_LIGHT
|
||||||
),
|
),
|
||||||
): bool,
|
): bool,
|
||||||
|
@ -320,7 +320,7 @@ class WorkdayOptionsFlowHandler(OptionsFlow):
|
|||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
combined_input: dict[str, Any] = {**self.options, **user_input}
|
combined_input: dict[str, Any] = {**self.config_entry.options, **user_input}
|
||||||
if CONF_PROVINCE not in user_input:
|
if CONF_PROVINCE not in user_input:
|
||||||
# Province not present, delete old value (if present) too
|
# Province not present, delete old value (if present) too
|
||||||
combined_input.pop(CONF_PROVINCE, None)
|
combined_input.pop(CONF_PROVINCE, None)
|
||||||
@ -357,23 +357,22 @@ class WorkdayOptionsFlowHandler(OptionsFlow):
|
|||||||
else:
|
else:
|
||||||
return self.async_create_entry(data=combined_input)
|
return self.async_create_entry(data=combined_input)
|
||||||
|
|
||||||
|
options = self.config_entry.options
|
||||||
schema: vol.Schema = await self.hass.async_add_executor_job(
|
schema: vol.Schema = await self.hass.async_add_executor_job(
|
||||||
add_province_and_language_to_schema,
|
add_province_and_language_to_schema,
|
||||||
DATA_SCHEMA_OPT,
|
DATA_SCHEMA_OPT,
|
||||||
self.options.get(CONF_COUNTRY),
|
options.get(CONF_COUNTRY),
|
||||||
)
|
)
|
||||||
|
|
||||||
new_schema = self.add_suggested_values_to_schema(
|
new_schema = self.add_suggested_values_to_schema(schema, user_input or options)
|
||||||
schema, user_input or self.options
|
|
||||||
)
|
|
||||||
LOGGER.debug("Errors have occurred in options %s", errors)
|
LOGGER.debug("Errors have occurred in options %s", errors)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
data_schema=new_schema,
|
data_schema=new_schema,
|
||||||
errors=errors,
|
errors=errors,
|
||||||
description_placeholders={
|
description_placeholders={
|
||||||
"name": self.options[CONF_NAME],
|
"name": options[CONF_NAME],
|
||||||
"country": self.options.get(CONF_COUNTRY),
|
"country": options.get(CONF_COUNTRY),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -194,6 +194,6 @@ class YouTubeOptionsFlowHandler(OptionsFlow):
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
self.options,
|
self.config_entry.options,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user