diff --git a/src/components/ha-blueprint-picker.ts b/src/components/ha-blueprint-picker.ts index b018d4c768..58a0f03f4a 100644 --- a/src/components/ha-blueprint-picker.ts +++ b/src/components/ha-blueprint-picker.ts @@ -5,7 +5,12 @@ import memoizeOne from "memoize-one"; import { fireEvent } from "../common/dom/fire_event"; import { stopPropagation } from "../common/dom/stop_propagation"; import { stringCompare } from "../common/string/compare"; -import { Blueprint, Blueprints, fetchBlueprints } from "../data/blueprint"; +import { + Blueprint, + BlueprintDomain, + Blueprints, + fetchBlueprints, +} from "../data/blueprint"; import { HomeAssistant } from "../types"; import "./ha-select"; @@ -17,7 +22,7 @@ class HaBluePrintPicker extends LitElement { @property() public value = ""; - @property() public domain = "automation"; + @property() public domain: BlueprintDomain = "automation"; @property() public blueprints?: Blueprints; diff --git a/src/data/blueprint.ts b/src/data/blueprint.ts index 2d98dc8c80..3f2b826953 100644 --- a/src/data/blueprint.ts +++ b/src/data/blueprint.ts @@ -1,6 +1,8 @@ import { HomeAssistant } from "../types"; import { Selector } from "./selector"; +export type BlueprintDomain = "automation" | "script"; + export type Blueprints = Record; export type BlueprintOrError = Blueprint | { error: string }; @@ -9,7 +11,7 @@ export interface Blueprint { } export interface BlueprintMetaData { - domain: string; + domain: BlueprintDomain; name: string; input?: Record; description?: string; @@ -30,7 +32,7 @@ export interface BlueprintImportResult { validation_errors: string[] | null; } -export const fetchBlueprints = (hass: HomeAssistant, domain: string) => +export const fetchBlueprints = (hass: HomeAssistant, domain: BlueprintDomain) => hass.callWS({ type: "blueprint/list", domain }); export const importBlueprint = (hass: HomeAssistant, url: string) => @@ -38,7 +40,7 @@ export const importBlueprint = (hass: HomeAssistant, url: string) => export const saveBlueprint = ( hass: HomeAssistant, - domain: string, + domain: BlueprintDomain, path: string, yaml: string, source_url?: string @@ -53,7 +55,7 @@ export const saveBlueprint = ( export const deleteBlueprint = ( hass: HomeAssistant, - domain: string, + domain: BlueprintDomain, path: string ) => hass.callWS({ diff --git a/src/panels/config/blueprint/ha-blueprint-overview.ts b/src/panels/config/blueprint/ha-blueprint-overview.ts index 0e65094222..3df0c44e41 100644 --- a/src/panels/config/blueprint/ha-blueprint-overview.ts +++ b/src/panels/config/blueprint/ha-blueprint-overview.ts @@ -25,6 +25,7 @@ import "../../../components/ha-icon-button"; import "../../../components/ha-svg-icon"; import { showAutomationEditor } from "../../../data/automation"; import { + BlueprintDomain, BlueprintMetaData, Blueprints, deleteBlueprint, @@ -124,7 +125,7 @@ class HaBlueprintOverview extends LitElement { title: this.hass.localize( "ui.panel.config.blueprint.overview.headers.type" ), - template: (type: string) => + template: (type: BlueprintDomain) => html`${this.hass.localize( `ui.panel.config.blueprint.overview.types.${type}` )}`, @@ -148,7 +149,7 @@ class HaBlueprintOverview extends LitElement { title: "", width: narrow ? undefined : "20%", type: narrow ? "icon-button" : undefined, - template: (_, blueprint: any) => + template: (_, blueprint: BlueprintMetaDataPath) => blueprint.error ? "" : narrow diff --git a/src/translations/en.json b/src/translations/en.json index 7c7cb97831..8c48ae19de 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2200,6 +2200,7 @@ "confirm_delete_header": "Delete this blueprint?", "confirm_delete_text": "Are you sure you want to delete this blueprint?", "add_blueprint": "Import blueprint", + "no_blueprints": "[%key:ui::panel::config::automation::editor::blueprint::no_blueprints%]", "create_automation": "Create automation", "create_script": "Create script", "delete_blueprint": "Delete blueprint",