From 8e3c665fd3a14bc2177191fe842dac2354a6a56d Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 12 Oct 2023 12:56:10 +0200 Subject: [PATCH] Only reload Withings config entry on reauth (#101638) * Only reload on reauth * Reload if entry is loaded * Make async_cloudhook_generate_url protected * Fix feedback --- homeassistant/components/withings/__init__.py | 20 ++++--------------- .../components/withings/config_flow.py | 1 + homeassistant/components/withings/const.py | 1 - 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index 16606a40645..225ff5603c4 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -43,14 +43,7 @@ from homeassistant.helpers.issue_registry import IssueSeverity, async_create_iss from homeassistant.helpers.typing import ConfigType from .api import ConfigEntryWithingsApi -from .const import ( - CONF_CLOUDHOOK_URL, - CONF_PROFILES, - CONF_USE_WEBHOOK, - DEFAULT_TITLE, - DOMAIN, - LOGGER, -) +from .const import CONF_PROFILES, CONF_USE_WEBHOOK, DEFAULT_TITLE, DOMAIN, LOGGER from .coordinator import WithingsDataUpdateCoordinator PLATFORMS = [Platform.BINARY_SENSOR, Platform.SENSOR] @@ -82,6 +75,7 @@ CONFIG_SCHEMA = vol.Schema( ) SUBSCRIBE_DELAY = timedelta(seconds=5) UNSUBSCRIBE_DELAY = timedelta(seconds=1) +CONF_CLOUDHOOK_URL = "cloudhook_url" async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: @@ -152,7 +146,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _: Any, ) -> None: if cloud.async_active_subscription(hass): - webhook_url = await async_cloudhook_generate_url(hass, entry) + webhook_url = await _async_cloudhook_generate_url(hass, entry) else: webhook_url = webhook_generate_url(hass, entry.data[CONF_WEBHOOK_ID]) @@ -200,7 +194,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: entry.async_on_unload(async_call_later(hass, 1, register_webhook)) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - entry.async_on_unload(entry.add_update_listener(update_listener)) return True @@ -214,11 +207,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: return unload_ok -async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None: - """Handle options update.""" - await hass.config_entries.async_reload(entry.entry_id) - - async def async_subscribe_webhooks( client: ConfigEntryWithingsApi, webhook_url: str ) -> None: @@ -266,7 +254,7 @@ async def async_unsubscribe_webhooks(client: ConfigEntryWithingsApi) -> None: ) -async def async_cloudhook_generate_url(hass: HomeAssistant, entry: ConfigEntry) -> str: +async def _async_cloudhook_generate_url(hass: HomeAssistant, entry: ConfigEntry) -> str: """Generate the full URL for a webhook_id.""" if CONF_CLOUDHOOK_URL not in entry.data: webhook_id = entry.data[CONF_WEBHOOK_ID] diff --git a/homeassistant/components/withings/config_flow.py b/homeassistant/components/withings/config_flow.py index 35a4582ae4d..8cab297b96a 100644 --- a/homeassistant/components/withings/config_flow.py +++ b/homeassistant/components/withings/config_flow.py @@ -76,6 +76,7 @@ class WithingsFlowHandler( self.hass.config_entries.async_update_entry( self.reauth_entry, data={**self.reauth_entry.data, **data} ) + await self.hass.config_entries.async_reload(self.reauth_entry.entry_id) return self.async_abort(reason="reauth_successful") return self.async_abort(reason="wrong_account") diff --git a/homeassistant/components/withings/const.py b/homeassistant/components/withings/const.py index 6129e0c4b29..545c7bfcb26 100644 --- a/homeassistant/components/withings/const.py +++ b/homeassistant/components/withings/const.py @@ -5,7 +5,6 @@ import logging DEFAULT_TITLE = "Withings" CONF_PROFILES = "profiles" CONF_USE_WEBHOOK = "use_webhook" -CONF_CLOUDHOOK_URL = "cloudhook_url" DATA_MANAGER = "data_manager"