mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Allow pasting more automation config formats (#25239)
This commit is contained in:
parent
b656ddc1f0
commit
1ba941282c
@ -27,7 +27,7 @@ import type {
|
|||||||
Trigger,
|
Trigger,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import { normalizeAutomationConfig } 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 { haStyle } from "../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import { documentationUrl } from "../../../util/documentation-url";
|
import { documentationUrl } from "../../../util/documentation-url";
|
||||||
@ -312,10 +312,59 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
|
|
||||||
const loaded: any = load(paste);
|
const loaded: any = load(paste);
|
||||||
if (loaded) {
|
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 {
|
try {
|
||||||
normalized = normalizeAutomationConfig(loaded);
|
normalized = normalizeAutomationConfig(config);
|
||||||
} catch (_err: any) {
|
} catch (_err: any) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user