From 61e4b56e1905102e92de9b620751807b45657785 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 14 Jun 2022 10:55:58 -0700 Subject: [PATCH] Guard withings accessing hass.data without it being set (#73454) Co-authored-by: Martin Hjelmare --- homeassistant/components/withings/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index 47702090cc0..6e8dee9a774 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -72,11 +72,12 @@ CONFIG_SCHEMA = vol.Schema( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Withings component.""" - conf = config.get(DOMAIN, {}) - if not (conf := config.get(DOMAIN, {})): + if not (conf := config.get(DOMAIN)): + # Apply the defaults. + conf = CONFIG_SCHEMA({DOMAIN: {}})[DOMAIN] + hass.data[DOMAIN] = {const.CONFIG: conf} return True - # Make the config available to the oauth2 config flow. hass.data[DOMAIN] = {const.CONFIG: conf} # Setup the oauth2 config flow.