Allow overriding blueprints (#18718)

This commit is contained in:
Paul Bottein 2023-11-25 11:49:58 +01:00 committed by GitHub
parent 6dafaac021
commit 0432cc95fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 4 deletions

View File

@ -29,6 +29,7 @@ export interface BlueprintInput {
export interface BlueprintImportResult { export interface BlueprintImportResult {
suggested_filename: string; suggested_filename: string;
raw_data: string; raw_data: string;
exists?: boolean;
blueprint: Blueprint; blueprint: Blueprint;
validation_errors: string[] | null; validation_errors: string[] | null;
} }
@ -44,7 +45,8 @@ export const saveBlueprint = (
domain: BlueprintDomain, domain: BlueprintDomain,
path: string, path: string,
yaml: string, yaml: string,
source_url?: string source_url?: string,
allow_override?: boolean
) => ) =>
hass.callWS({ hass.callWS({
type: "blueprint/save", type: "blueprint/save",
@ -52,6 +54,7 @@ export const saveBlueprint = (
path, path,
yaml, yaml,
source_url, source_url,
allow_override,
}); });
export const deleteBlueprint = ( export const deleteBlueprint = (

View File

@ -7,6 +7,7 @@ import "../../../components/ha-circular-progress";
import { createCloseHeading } from "../../../components/ha-dialog"; import { createCloseHeading } from "../../../components/ha-dialog";
import "../../../components/ha-expansion-panel"; import "../../../components/ha-expansion-panel";
import "../../../components/ha-markdown"; import "../../../components/ha-markdown";
import "../../../components/ha-alert";
import "../../../components/ha-textfield"; import "../../../components/ha-textfield";
import type { HaTextField } from "../../../components/ha-textfield"; import type { HaTextField } from "../../../components/ha-textfield";
import { import {
@ -105,7 +106,21 @@ class DialogImportBlueprint extends LitElement {
)} )}
> >
<pre>${this._result.raw_data}</pre> <pre>${this._result.raw_data}</pre>
</ha-expansion-panel>` </ha-expansion-panel>
${this._result?.exists
? html`
<ha-alert
alert-type="warning"
.title=${this.hass.localize(
"ui.panel.config.blueprint.add.override_title"
)}
>
${this.hass.localize(
"ui.panel.config.blueprint.add.override_description"
)}
</ha-alert>
`
: nothing} `
: html` : html`
<p> <p>
${this.hass.localize( ${this.hass.localize(
@ -175,7 +190,13 @@ class DialogImportBlueprint extends LitElement {
)} )}
></ha-circular-progress>` ></ha-circular-progress>`
: ""} : ""}
${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"
)}
</mwc-button> </mwc-button>
`} `}
</ha-dialog> </ha-dialog>
@ -214,7 +235,8 @@ class DialogImportBlueprint extends LitElement {
this._result!.blueprint.metadata.domain, this._result!.blueprint.metadata.domain,
filename, filename,
this._result!.raw_data, this._result!.raw_data,
this._result!.blueprint.metadata.source_url this._result!.blueprint.metadata.source_url,
this._result!.exists
); );
this._params.importedCallback(); this._params.importedCallback();
this.closeDialog(); this.closeDialog();

View File

@ -2961,6 +2961,9 @@
"import_btn": "Preview", "import_btn": "Preview",
"saving": "Importing blueprint…", "saving": "Importing blueprint…",
"save_btn": "Import 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.", "error_no_url": "Please enter the blueprint address.",
"unsupported_blueprint": "This blueprint is not supported", "unsupported_blueprint": "This blueprint is not supported",
"file_name": "Blueprint Path" "file_name": "Blueprint Path"