Only reload Withings config entry on reauth (#101638)
* Only reload on reauth * Reload if entry is loaded * Make async_cloudhook_generate_url protected * Fix feedbackpull/101872/head
parent
dcb3dc254d
commit
8e3c665fd3
|
@ -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]
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in New Issue