Improve code quality in yale_smart_alarm options flow (#129531)

* Improve code quality in yale_smart_alarm options flow

* mods

* Fix
This commit is contained in:
G Johansson 2024-11-03 21:04:53 +01:00 committed by GitHub
parent 6b33bf3961
commit ab5c65b08c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,7 +23,6 @@ from .const import (
CONF_AREA_ID,
CONF_LOCK_CODE_DIGITS,
DEFAULT_AREA_ID,
DEFAULT_LOCK_CODE_DIGITS,
DEFAULT_NAME,
DOMAIN,
LOGGER,
@ -44,6 +43,14 @@ DATA_SCHEMA_AUTH = vol.Schema(
}
)
OPTIONS_SCHEMA = vol.Schema(
{
vol.Optional(
CONF_LOCK_CODE_DIGITS,
): int,
}
)
class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
"""Handle a config flow for Yale integration."""
@ -54,7 +61,7 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
@callback
def async_get_options_flow(config_entry: ConfigEntry) -> YaleOptionsFlowHandler:
"""Get the options flow for this handler."""
return YaleOptionsFlowHandler(config_entry)
return YaleOptionsFlowHandler()
async def async_step_reauth(
self, entry_data: Mapping[str, Any]
@ -143,32 +150,18 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
class YaleOptionsFlowHandler(OptionsFlow):
"""Handle Yale options."""
def __init__(self, entry: ConfigEntry) -> None:
"""Initialize Yale options flow."""
self.entry = entry
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Manage Yale options."""
errors: dict[str, Any] = {}
if user_input:
if user_input is not None:
return self.async_create_entry(data=user_input)
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Optional(
CONF_LOCK_CODE_DIGITS,
description={
"suggested_value": self.entry.options.get(
CONF_LOCK_CODE_DIGITS, DEFAULT_LOCK_CODE_DIGITS
)
},
): int,
}
data_schema=self.add_suggested_values_to_schema(
OPTIONS_SCHEMA,
self.config_entry.options,
),
errors=errors,
)