Fix race condition when saving url config (#24687)

* Fix race condition when saving url config

* use SubscribeMixin
This commit is contained in:
Petar Petrov 2025-03-20 20:54:02 +02:00 committed by GitHub
parent fe17bb89eb
commit 4a166b6c23
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {