From 4a166b6c23b68b8cfbaaffb43750a20cd327f61d Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 20 Mar 2025 20:54:02 +0200 Subject: [PATCH] Fix race condition when saving url config (#24687) * Fix race condition when saving url config * use SubscribeMixin --- src/panels/config/network/ha-config-url-form.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/panels/config/network/ha-config-url-form.ts b/src/panels/config/network/ha-config-url-form.ts index ad0c9b8e9f..062c3f16e0 100644 --- a/src/panels/config/network/ha-config-url-form.ts +++ b/src/panels/config/network/ha-config-url-form.ts @@ -22,9 +22,10 @@ import { copyToClipboard } from "../../../common/util/copy-clipboard"; import { showToast } from "../../../util/toast"; import type { HaSwitch } from "../../../components/ha-switch"; import { obfuscateUrl } from "../../../util/url"; +import { SubscribeMixin } from "../../../mixins/subscribe-mixin"; @customElement("ha-config-url-form") -class ConfigUrlForm extends LitElement { +class ConfigUrlForm extends SubscribeMixin(LitElement) { @property({ attribute: false }) public hass!: HomeAssistant; @state() private _error?: string; @@ -49,6 +50,15 @@ class ConfigUrlForm extends LitElement { @state() private _cloudChecked = false; + protected hassSubscribe() { + return [ + this.hass.connection.subscribeEvents(() => { + // update the data when the urls are updated in core + this._fetchUrls(); + }, "core_config_updated"), + ]; + } + protected render() { const canEdit = ["storage", "default"].includes( this.hass.config.config_source @@ -361,7 +371,6 @@ class ConfigUrlForm extends LitElement { ? this._internal_url || null : null, }); - await this._fetchUrls(); } catch (err: any) { this._error = err.message || err; } finally {