From 0432cc95fc9c2104a03f2be419f433bcce397941 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Sat, 25 Nov 2023 11:49:58 +0100 Subject: [PATCH] Allow overriding blueprints (#18718) --- src/data/blueprint.ts | 5 +++- .../blueprint/dialog-import-blueprint.ts | 28 +++++++++++++++++-- src/translations/en.json | 3 ++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/data/blueprint.ts b/src/data/blueprint.ts index 315aa53044ee..f86f5743c3e8 100644 --- a/src/data/blueprint.ts +++ b/src/data/blueprint.ts @@ -29,6 +29,7 @@ export interface BlueprintInput { export interface BlueprintImportResult { suggested_filename: string; raw_data: string; + exists?: boolean; blueprint: Blueprint; validation_errors: string[] | null; } @@ -44,7 +45,8 @@ export const saveBlueprint = ( domain: BlueprintDomain, path: string, yaml: string, - source_url?: string + source_url?: string, + allow_override?: boolean ) => hass.callWS({ type: "blueprint/save", @@ -52,6 +54,7 @@ export const saveBlueprint = ( path, yaml, source_url, + allow_override, }); export const deleteBlueprint = ( diff --git a/src/panels/config/blueprint/dialog-import-blueprint.ts b/src/panels/config/blueprint/dialog-import-blueprint.ts index 779427086660..adb7d03ba8f7 100644 --- a/src/panels/config/blueprint/dialog-import-blueprint.ts +++ b/src/panels/config/blueprint/dialog-import-blueprint.ts @@ -7,6 +7,7 @@ import "../../../components/ha-circular-progress"; import { createCloseHeading } from "../../../components/ha-dialog"; import "../../../components/ha-expansion-panel"; import "../../../components/ha-markdown"; +import "../../../components/ha-alert"; import "../../../components/ha-textfield"; import type { HaTextField } from "../../../components/ha-textfield"; import { @@ -105,7 +106,21 @@ class DialogImportBlueprint extends LitElement { )} >
${this._result.raw_data}
- ` + + ${this._result?.exists + ? html` + + ${this.hass.localize( + "ui.panel.config.blueprint.add.override_description" + )} + + ` + : nothing} ` : html`

${this.hass.localize( @@ -175,7 +190,13 @@ class DialogImportBlueprint extends LitElement { )} >` : ""} - ${this.hass.localize("ui.panel.config.blueprint.add.save_btn")} + ${this._result.exists + ? this.hass.localize( + "ui.panel.config.blueprint.add.save_btn_override" + ) + : this.hass.localize( + "ui.panel.config.blueprint.add.save_btn" + )} `} @@ -214,7 +235,8 @@ class DialogImportBlueprint extends LitElement { this._result!.blueprint.metadata.domain, filename, this._result!.raw_data, - this._result!.blueprint.metadata.source_url + this._result!.blueprint.metadata.source_url, + this._result!.exists ); this._params.importedCallback(); this.closeDialog(); diff --git a/src/translations/en.json b/src/translations/en.json index 1c555bbbfc4a..21ffaa7549fa 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2961,6 +2961,9 @@ "import_btn": "Preview", "saving": "Importing blueprint…", "save_btn": "Import blueprint", + "save_btn_override": "Override blueprint", + "override_title": "This blueprint already exists", + "override_description": "Importing it will override the existing blueprint. If the updated blueprint is not compatible, it can break your automations. Automations will have to be adjusted manually.", "error_no_url": "Please enter the blueprint address.", "unsupported_blueprint": "This blueprint is not supported", "file_name": "Blueprint Path"