mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Allow pasting more automation config formats (#25239)
This commit is contained in:
parent
7d6bec01ae
commit
fd3502f3bc
@ -27,7 +27,7 @@ import type {
|
||||
Trigger,
|
||||
} from "../../../data/automation";
|
||||
import { normalizeAutomationConfig } from "../../../data/automation";
|
||||
import type { Action } from "../../../data/script";
|
||||
import { getActionType, type Action } from "../../../data/script";
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { documentationUrl } from "../../../util/documentation-url";
|
||||
@ -312,10 +312,59 @@ export class HaManualAutomationEditor extends LitElement {
|
||||
|
||||
const loaded: any = load(paste);
|
||||
if (loaded) {
|
||||
let normalized: AutomationConfig | undefined;
|
||||
let config = loaded;
|
||||
|
||||
if ("automation" in config) {
|
||||
config = config.automation;
|
||||
if (Array.isArray(config)) {
|
||||
config = config[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(config)) {
|
||||
if (config.length === 1) {
|
||||
config = config[0];
|
||||
} else {
|
||||
const newConfig: AutomationConfig = {
|
||||
triggers: [],
|
||||
conditions: [],
|
||||
actions: [],
|
||||
};
|
||||
let found = false;
|
||||
config.forEach((cfg: any) => {
|
||||
if ("trigger" in cfg) {
|
||||
found = true;
|
||||
(newConfig.triggers as Trigger[]).push(cfg);
|
||||
}
|
||||
if ("condition" in cfg) {
|
||||
found = true;
|
||||
(newConfig.conditions as Condition[]).push(cfg);
|
||||
}
|
||||
if (getActionType(cfg) !== "unknown") {
|
||||
found = true;
|
||||
(newConfig.actions as Action[]).push(cfg);
|
||||
}
|
||||
});
|
||||
if (found) {
|
||||
config = newConfig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ("trigger" in config) {
|
||||
config = { triggers: [config] };
|
||||
}
|
||||
if ("condition" in config) {
|
||||
config = { conditions: [config] };
|
||||
}
|
||||
if (getActionType(config) !== "unknown") {
|
||||
config = { actions: [config] };
|
||||
}
|
||||
|
||||
let normalized: AutomationConfig;
|
||||
|
||||
try {
|
||||
normalized = normalizeAutomationConfig(loaded);
|
||||
normalized = normalizeAutomationConfig(config);
|
||||
} catch (_err: any) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user