mirror of
https://github.com/home-assistant/frontend.git
synced 2025-09-29 23:09:55 +00:00
Compare commits
1 Commits
20250925.1
...
automation
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f8ecc7827e |
@@ -387,6 +387,18 @@ export const normalizeAutomationConfig = <
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We move all conditions into the action for display
|
||||||
|
if (config.conditions) {
|
||||||
|
if (config.actions) {
|
||||||
|
(config.actions as Action[]).unshift(
|
||||||
|
...(config.conditions as Condition[])
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
config.actions = config.conditions;
|
||||||
|
}
|
||||||
|
delete config.conditions;
|
||||||
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -24,6 +24,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
|||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { property, query, state } from "lit/decorators";
|
import { property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { isArray } from "@tsparticles/engine";
|
||||||
import { transform } from "../../../common/decorators/transform";
|
import { transform } from "../../../common/decorators/transform";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
@@ -43,6 +44,7 @@ import type {
|
|||||||
AutomationConfig,
|
AutomationConfig,
|
||||||
AutomationEntity,
|
AutomationEntity,
|
||||||
BlueprintAutomationConfig,
|
BlueprintAutomationConfig,
|
||||||
|
Condition,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import {
|
import {
|
||||||
deleteAutomation,
|
deleteAutomation,
|
||||||
@@ -1062,8 +1064,28 @@ export class HaAutomationEditor extends PreventUnsavedMixin(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Move conditions at top of action to automation condition key
|
||||||
|
const configToSave = { ...this._config! };
|
||||||
|
configToSave.conditions = !configToSave.conditions
|
||||||
|
? []
|
||||||
|
: isArray(configToSave.conditions)
|
||||||
|
? [...configToSave.conditions]
|
||||||
|
: [configToSave.conditions];
|
||||||
|
configToSave.actions = !configToSave.actions
|
||||||
|
? []
|
||||||
|
: isArray(configToSave.actions)
|
||||||
|
? [...configToSave.actions]
|
||||||
|
: [configToSave.actions];
|
||||||
|
|
||||||
|
while (
|
||||||
|
configToSave.actions.length > 0 &&
|
||||||
|
"condition" in configToSave.actions[0]
|
||||||
|
) {
|
||||||
|
configToSave.conditions.push(configToSave.actions.shift() as Condition);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await saveAutomationConfig(this.hass, id, this._config!);
|
await saveAutomationConfig(this.hass, id, configToSave);
|
||||||
|
|
||||||
if (this._entityRegistryUpdate !== undefined) {
|
if (this._entityRegistryUpdate !== undefined) {
|
||||||
let entityId = this._entityId;
|
let entityId = this._entityId;
|
||||||
|
@@ -45,8 +45,6 @@ import { documentationUrl } from "../../../util/documentation-url";
|
|||||||
import { showToast } from "../../../util/toast";
|
import { showToast } from "../../../util/toast";
|
||||||
import "./action/ha-automation-action";
|
import "./action/ha-automation-action";
|
||||||
import type HaAutomationAction from "./action/ha-automation-action";
|
import type HaAutomationAction from "./action/ha-automation-action";
|
||||||
import "./condition/ha-automation-condition";
|
|
||||||
import type HaAutomationCondition from "./condition/ha-automation-condition";
|
|
||||||
import "./ha-automation-sidebar";
|
import "./ha-automation-sidebar";
|
||||||
import type HaAutomationSidebar from "./ha-automation-sidebar";
|
import type HaAutomationSidebar from "./ha-automation-sidebar";
|
||||||
import { showPasteReplaceDialog } from "./paste-replace-dialog/show-dialog-paste-replace";
|
import { showPasteReplaceDialog } from "./paste-replace-dialog/show-dialog-paste-replace";
|
||||||
@@ -158,53 +156,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
sidebar
|
sidebar
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
|
|
||||||
<div class="header">
|
|
||||||
<h2 id="conditions-heading" class="name">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.conditions.header"
|
|
||||||
)}
|
|
||||||
<span class="small"
|
|
||||||
>(${this.hass.localize("ui.common.optional")})</span
|
|
||||||
>
|
|
||||||
</h2>
|
|
||||||
<a
|
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/condition/")}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>
|
|
||||||
<ha-icon-button
|
|
||||||
.path=${mdiHelpCircle}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.conditions.learn_more"
|
|
||||||
)}
|
|
||||||
></ha-icon-button>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
${!ensureArray(this.config.conditions)?.length
|
|
||||||
? html`<p>
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.conditions.description",
|
|
||||||
{ user: this.hass.user?.name || "Alice" }
|
|
||||||
)}
|
|
||||||
</p>`
|
|
||||||
: nothing}
|
|
||||||
|
|
||||||
<ha-automation-condition
|
|
||||||
role="region"
|
|
||||||
aria-labelledby="conditions-heading"
|
|
||||||
.conditions=${this.config.conditions || []}
|
|
||||||
.highlightedConditions=${this._pastedConfig?.conditions || []}
|
|
||||||
@value-changed=${this._conditionChanged}
|
|
||||||
.hass=${this.hass}
|
|
||||||
.disabled=${this.disabled || this.saving}
|
|
||||||
.narrow=${this.narrow}
|
|
||||||
@open-sidebar=${this._openSidebar}
|
|
||||||
@request-close-sidebar=${this._closeSidebar}
|
|
||||||
@close-sidebar=${this._handleCloseSidebar}
|
|
||||||
root
|
|
||||||
sidebar
|
|
||||||
></ha-automation-condition>
|
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2 id="actions-heading" class="name">
|
<h2 id="actions-heading" class="name">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
@@ -584,9 +535,9 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getCollapsableElements() {
|
private _getCollapsableElements() {
|
||||||
return this.shadowRoot!.querySelectorAll<
|
return this.shadowRoot!.querySelectorAll<HaAutomationAction>(
|
||||||
HaAutomationAction | HaAutomationCondition
|
"ha-automation-action"
|
||||||
>("ha-automation-action, ha-automation-condition");
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public expandAll() {
|
public expandAll() {
|
||||||
|
@@ -4109,9 +4109,6 @@
|
|||||||
},
|
},
|
||||||
"conditions": {
|
"conditions": {
|
||||||
"name": "Conditions",
|
"name": "Conditions",
|
||||||
"header": "And if",
|
|
||||||
"description": "All conditions added here need to be satisfied for the automation to run. A condition can be satisfied or not at any given time, for example: ''If {user} is home''. You can use building blocks to create more complex conditions.",
|
|
||||||
"learn_more": "Learn more about conditions",
|
|
||||||
"add": "Add condition",
|
"add": "Add condition",
|
||||||
"search": "Search condition",
|
"search": "Search condition",
|
||||||
"add_building_block": "Add building block",
|
"add_building_block": "Add building block",
|
||||||
|
Reference in New Issue
Block a user