mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
Allow pasting more script config (#25240)
* Allow pasting more script config * Update manual-script-editor.ts
This commit is contained in:
parent
1ba941282c
commit
50e39de974
@ -24,7 +24,11 @@ import "../../../components/ha-card";
|
||||
import "../../../components/ha-icon-button";
|
||||
import "../../../components/ha-markdown";
|
||||
import type { Action, Fields, ScriptConfig } from "../../../data/script";
|
||||
import { MODES, normalizeScriptConfig } from "../../../data/script";
|
||||
import {
|
||||
getActionType,
|
||||
MODES,
|
||||
normalizeScriptConfig,
|
||||
} from "../../../data/script";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { documentationUrl } from "../../../util/documentation-url";
|
||||
@ -236,10 +240,31 @@ export class HaManualScriptEditor extends LitElement {
|
||||
|
||||
const loaded: any = load(paste);
|
||||
if (loaded) {
|
||||
let config = loaded;
|
||||
|
||||
if ("script" in config) {
|
||||
config = config.script;
|
||||
if (Object.keys(config).length) {
|
||||
config = config[Object.keys(config)[0]];
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(config)) {
|
||||
if (config.length === 1) {
|
||||
config = config[0];
|
||||
} else {
|
||||
config = { sequence: config };
|
||||
}
|
||||
}
|
||||
|
||||
if (!["sequence", "unknown"].includes(getActionType(config))) {
|
||||
config = { sequence: [config] };
|
||||
}
|
||||
|
||||
let normalized: ScriptConfig | undefined;
|
||||
|
||||
try {
|
||||
normalized = normalizeScriptConfig(loaded);
|
||||
normalized = normalizeScriptConfig(config);
|
||||
} catch (_err: any) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user