Fix key type errors for blueprints

This commit is contained in:
Steve Repsher 2022-07-13 13:19:43 -04:00
parent e241b20378
commit b444d0030f
No known key found for this signature in database
GPG Key ID: 776C4F2DACF6131B
4 changed files with 17 additions and 8 deletions

View File

@ -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;

View File

@ -1,6 +1,8 @@
import { HomeAssistant } from "../types";
import { Selector } from "./selector";
export type BlueprintDomain = "automation" | "script";
export type Blueprints = Record<string, BlueprintOrError>;
export type BlueprintOrError = Blueprint | { error: string };
@ -9,7 +11,7 @@ export interface Blueprint {
}
export interface BlueprintMetaData {
domain: string;
domain: BlueprintDomain;
name: string;
input?: Record<string, BlueprintInput | null>;
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<Blueprints>({ 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<BlueprintImportResult>({

View File

@ -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

View File

@ -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",