Fix duplicate agents ids during onboarding (#23357)

Fix duplicate agents ids during onboardind
This commit is contained in:
Paul Bottein 2024-12-20 14:04:32 +01:00 committed by GitHub
parent 907299b139
commit ecc704e6ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 7 deletions

View File

@ -116,10 +116,11 @@ class HaBackupConfigAgents extends LitElement {
this.value = this._value.filter((agent) => agent !== agentId); this.value = this._value.filter((agent) => agent !== agentId);
} }
// Ensure agents exist in the list // Ensure we don't have duplicates, agents exist in the list and cloud is logged in
this.value = this.value this.value = [...new Set(this.value)]
.filter((agent) => this._agentIds.some((id) => id === agent)) .filter((agent) => this._agentIds.some((id) => id === agent))
.filter((id) => id !== CLOUD_AGENT || this.cloudStatus); .filter((id) => id !== CLOUD_AGENT || this.cloudStatus.logged_in);
fireEvent(this, "value-changed", { value: this.value }); fireEvent(this, "value-changed", { value: this.value });
} }

View File

@ -96,18 +96,26 @@ class DialogBackupOnboarding extends LitElement implements HassDialog {
this._step = this._steps[0]; this._step = this._steps[0];
this._config = RECOMMENDED_CONFIG; this._config = RECOMMENDED_CONFIG;
const agents: string[] = [];
// Enable local location by default // Enable local location by default
if (isComponentLoaded(this.hass, "hassio")) { if (isComponentLoaded(this.hass, "hassio")) {
this._config.create_backup.agent_ids.push(HASSIO_LOCAL_AGENT); agents.push(HASSIO_LOCAL_AGENT);
} else { } else {
this._config.create_backup.agent_ids.push(CORE_LOCAL_AGENT); agents.push(CORE_LOCAL_AGENT);
} }
// Enable cloud location if logged in // Enable cloud location if logged in
if (this._params.cloudStatus.logged_in) { if (this._params.cloudStatus.logged_in) {
this._config.create_backup.agent_ids.push(CLOUD_AGENT); agents.push(CLOUD_AGENT);
} }
this._config.create_backup.password = generateEncryptionKey(); this._config = {
...this._config,
create_backup: {
...this._config.create_backup,
agent_ids: agents,
password: generateEncryptionKey(),
},
};
this._opened = true; this._opened = true;
} }