Skip to content

Commit

Permalink
Allow overriding blueprints (#18718)
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored Nov 25, 2023
1 parent 6dafaac commit 0432cc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/data/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface BlueprintInput {
export interface BlueprintImportResult {
suggested_filename: string;
raw_data: string;
exists?: boolean;
blueprint: Blueprint;
validation_errors: string[] | null;
}
Expand All @@ -44,14 +45,16 @@ export const saveBlueprint = (
domain: BlueprintDomain,
path: string,
yaml: string,
source_url?: string
source_url?: string,
allow_override?: boolean
) =>
hass.callWS({
type: "blueprint/save",
domain,
path,
yaml,
source_url,
allow_override,
});

export const deleteBlueprint = (
Expand Down
28 changes: 25 additions & 3 deletions src/panels/config/blueprint/dialog-import-blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -105,7 +106,21 @@ class DialogImportBlueprint extends LitElement {
)}
>
<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`
<p>
${this.hass.localize(
Expand Down Expand Up @@ -175,7 +190,13 @@ class DialogImportBlueprint extends LitElement {
)}
></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>
`}
</ha-dialog>
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0432cc9

Please sign in to comment.