Skip to content

Commit

Permalink
fix: user input malformed bug in config flow (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Jul 21, 2021
2 parents 1dbdea3 + 17fd86e commit d0908f0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions custom_components/mail_and_packages/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def _get_schema_step_1(hass: Any, user_input: list, default_dict: list) -> Any:
if user_input is None:
user_input = {}

def _get_default(key):
def _get_default(key: str, fallback_default: Any = None) -> None:
"""Gets default value for key."""
return user_input.get(key, default_dict.get(key))
return user_input.get(key, default_dict.get(key, fallback_default))

return vol.Schema(
{
Expand All @@ -168,9 +168,9 @@ def _get_schema_step_2(
if user_input is None:
user_input = {}

def _get_default(key):
def _get_default(key: str, fallback_default: Any = None) -> None:
"""Gets default value for key."""
return user_input.get(key, default_dict.get(key))
return user_input.get(key, default_dict.get(key, fallback_default))

return vol.Schema(
{
Expand All @@ -185,7 +185,9 @@ def _get_default(key):
vol.Required(
CONF_RESOURCES, default=_get_default(CONF_RESOURCES)
): cv.multi_select(get_resources()),
vol.Optional(CONF_AMAZON_FWDS, default=_get_default(CONF_AMAZON_FWDS)): str,
vol.Optional(
CONF_AMAZON_FWDS, default=_get_default(CONF_AMAZON_FWDS, "")
): str,
vol.Optional(
CONF_SCAN_INTERVAL, default=_get_default(CONF_SCAN_INTERVAL)
): vol.All(vol.Coerce(int)),
Expand Down Expand Up @@ -213,14 +215,15 @@ def _get_schema_step_3(
if user_input is None:
user_input = {}

def _get_default(key):
def _get_default(key: str, fallback_default: Any = None) -> None:
"""Gets default value for key."""
return user_input.get(key, default_dict.get(key))
return user_input.get(key, default_dict.get(key, fallback_default))

return vol.Schema(
{
vol.Optional(
CONF_CUSTOM_IMG_FILE, default=_get_default(CONF_CUSTOM_IMG_FILE)
CONF_CUSTOM_IMG_FILE,
default=_get_default(CONF_CUSTOM_IMG_FILE, DEFAULT_CUSTOM_IMG_FILE),
): str,
}
)
Expand Down

0 comments on commit d0908f0

Please sign in to comment.