From f8630ccc24cc99ab666f7cf03f5565ff0485abf5 Mon Sep 17 00:00:00 2001 From: firstof9 Date: Wed, 21 Jul 2021 11:27:22 -0700 Subject: [PATCH 1/2] fix: user input malformed bug in config flow --- custom_components/mail_and_packages/config_flow.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/custom_components/mail_and_packages/config_flow.py b/custom_components/mail_and_packages/config_flow.py index 2675b044..8438effc 100644 --- a/custom_components/mail_and_packages/config_flow.py +++ b/custom_components/mail_and_packages/config_flow.py @@ -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( { @@ -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)), @@ -220,7 +222,8 @@ def _get_default(key): 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, } ) From 17fd86e67de8ab0d61d17bec5b789fdfd0c8d49a Mon Sep 17 00:00:00 2001 From: firstof9 Date: Wed, 21 Jul 2021 11:37:11 -0700 Subject: [PATCH 2/2] update the function where missing --- custom_components/mail_and_packages/config_flow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/mail_and_packages/config_flow.py b/custom_components/mail_and_packages/config_flow.py index 8438effc..cf96ba9f 100644 --- a/custom_components/mail_and_packages/config_flow.py +++ b/custom_components/mail_and_packages/config_flow.py @@ -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( { @@ -215,9 +215,9 @@ 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( {