mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Simplify usage on clipboard for automations and scripts (#16989)
This commit is contained in:
parent
eb552530e2
commit
1ee67937ec
@ -387,7 +387,7 @@ export const testCondition = (
|
|||||||
variables,
|
variables,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type Clipboard = {
|
export type AutomationClipboard = {
|
||||||
trigger?: Trigger;
|
trigger?: Trigger;
|
||||||
condition?: Condition;
|
condition?: Condition;
|
||||||
action?: Action;
|
action?: Action;
|
||||||
|
@ -3,9 +3,9 @@ import "@material/mwc-list/mwc-list-item";
|
|||||||
import {
|
import {
|
||||||
mdiAlertCircleCheck,
|
mdiAlertCircleCheck,
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
|
||||||
mdiContentCopy,
|
mdiContentCopy,
|
||||||
mdiContentCut,
|
mdiContentCut,
|
||||||
|
mdiContentDuplicate,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
mdiPlay,
|
mdiPlay,
|
||||||
@ -14,17 +14,19 @@ import {
|
|||||||
mdiSort,
|
mdiSort,
|
||||||
mdiStopCircleOutline,
|
mdiStopCircleOutline,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
|
import deepClone from "deep-clone-simple";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
|
||||||
LitElement,
|
LitElement,
|
||||||
nothing,
|
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
|
css,
|
||||||
|
html,
|
||||||
|
nothing,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
||||||
@ -36,12 +38,12 @@ import "../../../../components/ha-expansion-panel";
|
|||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-icon-button";
|
||||||
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
||||||
import { ACTION_TYPES, YAML_ONLY_ACTION_TYPES } from "../../../../data/action";
|
import { ACTION_TYPES, YAML_ONLY_ACTION_TYPES } from "../../../../data/action";
|
||||||
|
import { AutomationClipboard } from "../../../../data/automation";
|
||||||
import { validateConfig } from "../../../../data/config";
|
import { validateConfig } from "../../../../data/config";
|
||||||
import {
|
import {
|
||||||
EntityRegistryEntry,
|
EntityRegistryEntry,
|
||||||
subscribeEntityRegistry,
|
subscribeEntityRegistry,
|
||||||
} from "../../../../data/entity_registry";
|
} from "../../../../data/entity_registry";
|
||||||
import { Clipboard } from "../../../../data/automation";
|
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
NonConditionAction,
|
NonConditionAction,
|
||||||
@ -127,7 +129,13 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
@storage({
|
||||||
|
key: "automationClipboard",
|
||||||
|
state: false,
|
||||||
|
subscribe: true,
|
||||||
|
storage: "sessionStorage",
|
||||||
|
})
|
||||||
|
public _clipboard?: AutomationClipboard;
|
||||||
|
|
||||||
@state() private _entityReg: EntityRegistryEntry[] = [];
|
@state() private _entityReg: EntityRegistryEntry[] = [];
|
||||||
|
|
||||||
@ -396,7 +404,6 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
narrow: this.narrow,
|
narrow: this.narrow,
|
||||||
reOrderMode: this.reOrderMode,
|
reOrderMode: this.reOrderMode,
|
||||||
disabled: this.disabled,
|
disabled: this.disabled,
|
||||||
clipboard: this.clipboard,
|
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
@ -431,10 +438,10 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
fireEvent(this, "duplicate");
|
fireEvent(this, "duplicate");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
fireEvent(this, "set-clipboard", { action: this.action });
|
this._setClipboard();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
fireEvent(this, "set-clipboard", { action: this.action });
|
this._setClipboard();
|
||||||
fireEvent(this, "value-changed", { value: null });
|
fireEvent(this, "value-changed", { value: null });
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
@ -454,6 +461,13 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setClipboard() {
|
||||||
|
this._clipboard = {
|
||||||
|
...this._clipboard,
|
||||||
|
action: deepClone(this.action),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private _onDisable() {
|
private _onDisable() {
|
||||||
const enabled = !(this.action.enabled ?? true);
|
const enabled = !(this.action.enabled ?? true);
|
||||||
const value = { ...this.action, enabled };
|
const value = { ...this.action, enabled };
|
||||||
|
@ -29,7 +29,7 @@ import type { HaSelect } from "../../../../components/ha-select";
|
|||||||
import "../../../../components/ha-svg-icon";
|
import "../../../../components/ha-svg-icon";
|
||||||
import { ACTION_TYPES } from "../../../../data/action";
|
import { ACTION_TYPES } from "../../../../data/action";
|
||||||
import { Action } from "../../../../data/script";
|
import { Action } from "../../../../data/script";
|
||||||
import { Clipboard } from "../../../../data/automation";
|
import { AutomationClipboard } from "../../../../data/automation";
|
||||||
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
import {
|
import {
|
||||||
loadSortable,
|
loadSortable,
|
||||||
@ -52,6 +52,7 @@ import "./types/ha-automation-action-service";
|
|||||||
import "./types/ha-automation-action-stop";
|
import "./types/ha-automation-action-stop";
|
||||||
import "./types/ha-automation-action-wait_for_trigger";
|
import "./types/ha-automation-action-wait_for_trigger";
|
||||||
import "./types/ha-automation-action-wait_template";
|
import "./types/ha-automation-action-wait_template";
|
||||||
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
|
|
||||||
const PASTE_VALUE = "__paste__";
|
const PASTE_VALUE = "__paste__";
|
||||||
|
|
||||||
@ -69,7 +70,13 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
@storage({
|
||||||
|
key: "automationClipboard",
|
||||||
|
state: true,
|
||||||
|
subscribe: true,
|
||||||
|
storage: "sessionStorage",
|
||||||
|
})
|
||||||
|
public _clipboard?: AutomationClipboard;
|
||||||
|
|
||||||
private _focusLastActionOnChange = false;
|
private _focusLastActionOnChange = false;
|
||||||
|
|
||||||
@ -113,7 +120,6 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
@duplicate=${this._duplicateAction}
|
@duplicate=${this._duplicateAction}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
@re-order=${this._enterReOrderMode}
|
@re-order=${this._enterReOrderMode}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
>
|
>
|
||||||
${this.reOrderMode
|
${this.reOrderMode
|
||||||
@ -162,14 +168,14 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
||||||
</ha-button>
|
</ha-button>
|
||||||
${this.clipboard?.action
|
${this._clipboard?.action
|
||||||
? html` <mwc-list-item .value=${PASTE_VALUE} graphic="icon">
|
? html` <mwc-list-item .value=${PASTE_VALUE} graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.paste"
|
"ui.panel.config.automation.editor.actions.paste"
|
||||||
)}
|
)}
|
||||||
(${this.hass.localize(
|
(${this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.actions.type.${getType(
|
`ui.panel.config.automation.editor.actions.type.${getType(
|
||||||
this.clipboard.action
|
this._clipboard.action
|
||||||
)}.label`
|
)}.label`
|
||||||
)})
|
)})
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiContentPaste}></ha-svg-icon
|
<ha-svg-icon slot="graphic" .path=${mdiContentPaste}></ha-svg-icon
|
||||||
@ -260,7 +266,7 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
|
|
||||||
let actions: Action[];
|
let actions: Action[];
|
||||||
if (action === PASTE_VALUE) {
|
if (action === PASTE_VALUE) {
|
||||||
actions = this.actions.concat(deepClone(this.clipboard!.action));
|
actions = this.actions.concat(deepClone(this._clipboard!.action));
|
||||||
} else {
|
} else {
|
||||||
const elClass = customElements.get(
|
const elClass = customElements.get(
|
||||||
`ha-automation-action-${action}`
|
`ha-automation-action-${action}`
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { mdiDelete, mdiPlus } from "@mdi/js";
|
import { mdiDelete, mdiPlus } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { CSSResultGroup, LitElement, css, html } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
|
||||||
import { ensureArray } from "../../../../../common/array/ensure-array";
|
import { ensureArray } from "../../../../../common/array/ensure-array";
|
||||||
import "../../../../../components/ha-icon-button";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import "../../../../../components/ha-button";
|
import "../../../../../components/ha-button";
|
||||||
import { Condition, Clipboard } from "../../../../../data/automation";
|
import "../../../../../components/ha-icon-button";
|
||||||
|
import { Condition } from "../../../../../data/automation";
|
||||||
import { Action, ChooseAction } from "../../../../../data/script";
|
import { Action, ChooseAction } from "../../../../../data/script";
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
@ -23,8 +23,6 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@state() private _showDefault = false;
|
@state() private _showDefault = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { choose: [{ conditions: [], sequence: [] }] };
|
return { choose: [{ conditions: [], sequence: [] }] };
|
||||||
}
|
}
|
||||||
@ -65,7 +63,6 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
<h3>
|
<h3>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
@ -80,7 +77,6 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
</div>
|
</div>
|
||||||
</ha-card>`
|
</ha-card>`
|
||||||
@ -109,7 +105,6 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._defaultChanged}
|
@value-changed=${this._defaultChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`
|
`
|
||||||
: html`<div class="link-button-row">
|
: html`<div class="link-button-row">
|
||||||
|
@ -6,7 +6,7 @@ import { stringCompare } from "../../../../../common/string/compare";
|
|||||||
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
import type { LocalizeFunc } from "../../../../../common/translations/localize";
|
||||||
import "../../../../../components/ha-select";
|
import "../../../../../components/ha-select";
|
||||||
import type { HaSelect } from "../../../../../components/ha-select";
|
import type { HaSelect } from "../../../../../components/ha-select";
|
||||||
import type { Condition, Clipboard } from "../../../../../data/automation";
|
import type { Condition } from "../../../../../data/automation";
|
||||||
import { CONDITION_TYPES } from "../../../../../data/condition";
|
import { CONDITION_TYPES } from "../../../../../data/condition";
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import "../../condition/ha-automation-condition-editor";
|
import "../../condition/ha-automation-condition-editor";
|
||||||
@ -20,8 +20,6 @@ export class HaConditionAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property() public action!: Condition;
|
@property() public action!: Condition;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { condition: "state" };
|
return { condition: "state" };
|
||||||
}
|
}
|
||||||
@ -51,7 +49,6 @@ export class HaConditionAction extends LitElement implements ActionElement {
|
|||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-condition-editor>
|
></ha-automation-condition-editor>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import "../../../../../components/ha-textfield";
|
||||||
import { Action, IfAction } from "../../../../../data/script";
|
import { Action, IfAction } from "../../../../../data/script";
|
||||||
import type { Clipboard } from "../../../../../data/automation";
|
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import type { Condition } from "../../../../lovelace/common/validate-condition";
|
import type { Condition } from "../../../../lovelace/common/validate-condition";
|
||||||
import "../ha-automation-action";
|
import "../ha-automation-action";
|
||||||
import "../../../../../components/ha-textfield";
|
|
||||||
import type { ActionElement } from "../ha-automation-action-row";
|
import type { ActionElement } from "../ha-automation-action-row";
|
||||||
|
|
||||||
@customElement("ha-automation-action-if")
|
@customElement("ha-automation-action-if")
|
||||||
@ -20,8 +19,6 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
@state() private _showElse = false;
|
@state() private _showElse = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
@ -46,7 +43,6 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._ifChanged}
|
@value-changed=${this._ifChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
|
|
||||||
@ -61,7 +57,6 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._thenChanged}
|
@value-changed=${this._thenChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
${this._showElse || action.else
|
${this._showElse || action.else
|
||||||
@ -77,7 +72,6 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._elseChanged}
|
@value-changed=${this._elseChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`
|
`
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
import { CSSResultGroup, html, LitElement } from "lit";
|
import { CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import "../../../../../components/ha-textfield";
|
||||||
import { Action, ParallelAction } from "../../../../../data/script";
|
import { Action, ParallelAction } from "../../../../../data/script";
|
||||||
import type { Clipboard } from "../../../../../data/automation";
|
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import "../ha-automation-action";
|
import "../ha-automation-action";
|
||||||
import "../../../../../components/ha-textfield";
|
|
||||||
import type { ActionElement } from "../ha-automation-action-row";
|
import type { ActionElement } from "../ha-automation-action-row";
|
||||||
|
|
||||||
@customElement("ha-automation-action-parallel")
|
@customElement("ha-automation-action-parallel")
|
||||||
@ -19,8 +18,6 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
parallel: [],
|
parallel: [],
|
||||||
@ -37,7 +34,6 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
|||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._actionsChanged}
|
@value-changed=${this._actionsChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`;
|
`;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import "../../../../../components/ha-textfield";
|
||||||
import {
|
import {
|
||||||
Action,
|
Action,
|
||||||
CountRepeat,
|
CountRepeat,
|
||||||
@ -8,12 +9,10 @@ import {
|
|||||||
UntilRepeat,
|
UntilRepeat,
|
||||||
WhileRepeat,
|
WhileRepeat,
|
||||||
} from "../../../../../data/script";
|
} from "../../../../../data/script";
|
||||||
import type { Clipboard } from "../../../../../data/automation";
|
|
||||||
import { haStyle } from "../../../../../resources/styles";
|
import { haStyle } from "../../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import type { Condition } from "../../../../lovelace/common/validate-condition";
|
import type { Condition } from "../../../../lovelace/common/validate-condition";
|
||||||
import "../ha-automation-action";
|
import "../ha-automation-action";
|
||||||
import "../../../../../components/ha-textfield";
|
|
||||||
import type { ActionElement } from "../ha-automation-action-row";
|
import type { ActionElement } from "../ha-automation-action-row";
|
||||||
|
|
||||||
const OPTIONS = ["count", "while", "until"] as const;
|
const OPTIONS = ["count", "while", "until"] as const;
|
||||||
@ -30,8 +29,6 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { repeat: { count: 2, sequence: [] } };
|
return { repeat: { count: 2, sequence: [] } };
|
||||||
}
|
}
|
||||||
@ -85,7 +82,6 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-condition>`
|
></ha-automation-condition>`
|
||||||
: type === "until"
|
: type === "until"
|
||||||
? html` <h3>
|
? html` <h3>
|
||||||
@ -99,7 +95,6 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-condition>`
|
></ha-automation-condition>`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
@ -114,7 +109,6 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`;
|
`;
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
import "../../../../../components/ha-textfield";
|
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { ensureArray } from "../../../../../common/array/ensure-array";
|
||||||
|
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
|
import { TimeChangedEvent } from "../../../../../components/ha-base-time-input";
|
||||||
|
import "../../../../../components/ha-duration-input";
|
||||||
import "../../../../../components/ha-formfield";
|
import "../../../../../components/ha-formfield";
|
||||||
|
import "../../../../../components/ha-textfield";
|
||||||
import { WaitForTriggerAction } from "../../../../../data/script";
|
import { WaitForTriggerAction } from "../../../../../data/script";
|
||||||
import type { Clipboard } from "../../../../../data/automation";
|
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import "../../trigger/ha-automation-trigger";
|
import "../../trigger/ha-automation-trigger";
|
||||||
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
import { ActionElement, handleChangeEvent } from "../ha-automation-action-row";
|
||||||
import "../../../../../components/ha-duration-input";
|
|
||||||
import { createDurationData } from "../../../../../common/datetime/create_duration_data";
|
|
||||||
import { TimeChangedEvent } from "../../../../../components/ha-base-time-input";
|
|
||||||
import { ensureArray } from "../../../../../common/array/ensure-array";
|
|
||||||
|
|
||||||
@customElement("ha-automation-action-wait_for_trigger")
|
@customElement("ha-automation-action-wait_for_trigger")
|
||||||
export class HaWaitForTriggerAction
|
export class HaWaitForTriggerAction
|
||||||
@ -26,8 +25,6 @@ export class HaWaitForTriggerAction
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { wait_for_trigger: [] };
|
return { wait_for_trigger: [] };
|
||||||
}
|
}
|
||||||
@ -65,7 +62,6 @@ export class HaWaitForTriggerAction
|
|||||||
.name=${"wait_for_trigger"}
|
.name=${"wait_for_trigger"}
|
||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import memoizeOne from "memoize-one";
|
|||||||
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-yaml-editor";
|
import "../../../../components/ha-yaml-editor";
|
||||||
import type { Condition, Clipboard } from "../../../../data/automation";
|
import type { Condition } from "../../../../data/automation";
|
||||||
import { expandConditionWithShorthand } from "../../../../data/automation";
|
import { expandConditionWithShorthand } from "../../../../data/automation";
|
||||||
import { haStyle } from "../../../../resources/styles";
|
import { haStyle } from "../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
@ -32,8 +32,6 @@ export default class HaAutomationConditionEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
private _processedCondition = memoizeOne((condition) =>
|
private _processedCondition = memoizeOne((condition) =>
|
||||||
expandConditionWithShorthand(condition)
|
expandConditionWithShorthand(condition)
|
||||||
);
|
);
|
||||||
@ -72,7 +70,6 @@ export default class HaAutomationConditionEditor extends LitElement {
|
|||||||
condition: condition,
|
condition: condition,
|
||||||
reOrderMode: this.reOrderMode,
|
reOrderMode: this.reOrderMode,
|
||||||
disabled: this.disabled,
|
disabled: this.disabled,
|
||||||
clipboard: this.clipboard,
|
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,9 +3,9 @@ import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
|||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import {
|
import {
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
|
||||||
mdiContentCopy,
|
mdiContentCopy,
|
||||||
mdiContentCut,
|
mdiContentCut,
|
||||||
|
mdiContentDuplicate,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
mdiFlask,
|
mdiFlask,
|
||||||
@ -14,9 +14,11 @@ import {
|
|||||||
mdiSort,
|
mdiSort,
|
||||||
mdiStopCircleOutline,
|
mdiStopCircleOutline,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
|
import deepClone from "deep-clone-simple";
|
||||||
|
import { CSSResultGroup, LitElement, css, html, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
||||||
import { handleStructError } from "../../../../common/structs/handle-errors";
|
import { handleStructError } from "../../../../common/structs/handle-errors";
|
||||||
@ -24,8 +26,8 @@ import "../../../../components/ha-button-menu";
|
|||||||
import "../../../../components/ha-card";
|
import "../../../../components/ha-card";
|
||||||
import "../../../../components/ha-expansion-panel";
|
import "../../../../components/ha-expansion-panel";
|
||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-icon-button";
|
||||||
|
import type { AutomationClipboard } from "../../../../data/automation";
|
||||||
import { Condition, testCondition } from "../../../../data/automation";
|
import { Condition, testCondition } from "../../../../data/automation";
|
||||||
import type { Clipboard } from "../../../../data/automation";
|
|
||||||
import { describeCondition } from "../../../../data/automation_i18n";
|
import { describeCondition } from "../../../../data/automation_i18n";
|
||||||
import { CONDITION_TYPES } from "../../../../data/condition";
|
import { CONDITION_TYPES } from "../../../../data/condition";
|
||||||
import { validateConfig } from "../../../../data/config";
|
import { validateConfig } from "../../../../data/config";
|
||||||
@ -83,7 +85,13 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@property({ type: Boolean }) public disabled = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
@storage({
|
||||||
|
key: "automationClipboard",
|
||||||
|
state: false,
|
||||||
|
subscribe: true,
|
||||||
|
storage: "sessionStorage",
|
||||||
|
})
|
||||||
|
public _clipboard?: AutomationClipboard;
|
||||||
|
|
||||||
@state() private _yamlMode = false;
|
@state() private _yamlMode = false;
|
||||||
|
|
||||||
@ -290,7 +298,6 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.condition=${this.condition}
|
.condition=${this.condition}
|
||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
></ha-automation-condition-editor>
|
></ha-automation-condition-editor>
|
||||||
</div>
|
</div>
|
||||||
</ha-expansion-panel>
|
</ha-expansion-panel>
|
||||||
@ -343,10 +350,10 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
fireEvent(this, "duplicate");
|
fireEvent(this, "duplicate");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
fireEvent(this, "set-clipboard", { condition: this.condition });
|
this._setClipboard();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
fireEvent(this, "set-clipboard", { condition: this.condition });
|
this._setClipboard();
|
||||||
fireEvent(this, "value-changed", { value: null });
|
fireEvent(this, "value-changed", { value: null });
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
@ -366,6 +373,13 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setClipboard() {
|
||||||
|
this._clipboard = {
|
||||||
|
...this._clipboard,
|
||||||
|
condition: deepClone(this.condition),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private _onDisable() {
|
private _onDisable() {
|
||||||
const enabled = !(this.condition.enabled ?? true);
|
const enabled = !(this.condition.enabled ?? true);
|
||||||
const value = { ...this.condition, enabled };
|
const value = { ...this.condition, enabled };
|
||||||
|
@ -3,9 +3,9 @@ import type { ActionDetail } from "@material/mwc-list";
|
|||||||
import {
|
import {
|
||||||
mdiArrowDown,
|
mdiArrowDown,
|
||||||
mdiArrowUp,
|
mdiArrowUp,
|
||||||
|
mdiContentPaste,
|
||||||
mdiDrag,
|
mdiDrag,
|
||||||
mdiPlus,
|
mdiPlus,
|
||||||
mdiContentPaste,
|
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import deepClone from "deep-clone-simple";
|
import deepClone from "deep-clone-simple";
|
||||||
import {
|
import {
|
||||||
@ -13,8 +13,8 @@ import {
|
|||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
html,
|
||||||
LitElement,
|
LitElement,
|
||||||
PropertyValues,
|
|
||||||
nothing,
|
nothing,
|
||||||
|
PropertyValues,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { repeat } from "lit/directives/repeat";
|
import { repeat } from "lit/directives/repeat";
|
||||||
@ -24,7 +24,10 @@ import { fireEvent } from "../../../../common/dom/fire_event";
|
|||||||
import "../../../../components/ha-button";
|
import "../../../../components/ha-button";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
import "../../../../components/ha-svg-icon";
|
import "../../../../components/ha-svg-icon";
|
||||||
import type { Condition, Clipboard } from "../../../../data/automation";
|
import type {
|
||||||
|
AutomationClipboard,
|
||||||
|
Condition,
|
||||||
|
} from "../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-condition-row";
|
import "./ha-automation-condition-row";
|
||||||
import type HaAutomationConditionRow from "./ha-automation-condition-row";
|
import type HaAutomationConditionRow from "./ha-automation-condition-row";
|
||||||
@ -49,6 +52,7 @@ import "./types/ha-automation-condition-template";
|
|||||||
import "./types/ha-automation-condition-time";
|
import "./types/ha-automation-condition-time";
|
||||||
import "./types/ha-automation-condition-trigger";
|
import "./types/ha-automation-condition-trigger";
|
||||||
import "./types/ha-automation-condition-zone";
|
import "./types/ha-automation-condition-zone";
|
||||||
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
|
|
||||||
const PASTE_VALUE = "__paste__";
|
const PASTE_VALUE = "__paste__";
|
||||||
|
|
||||||
@ -64,7 +68,13 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
@storage({
|
||||||
|
key: "automationClipboard",
|
||||||
|
state: true,
|
||||||
|
subscribe: true,
|
||||||
|
storage: "sessionStorage",
|
||||||
|
})
|
||||||
|
public _clipboard?: AutomationClipboard;
|
||||||
|
|
||||||
private _focusLastConditionOnChange = false;
|
private _focusLastConditionOnChange = false;
|
||||||
|
|
||||||
@ -157,7 +167,6 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
@move-condition=${this._move}
|
@move-condition=${this._move}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
@re-order=${this._enterReOrderMode}
|
@re-order=${this._enterReOrderMode}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
>
|
>
|
||||||
${this.reOrderMode
|
${this.reOrderMode
|
||||||
@ -206,13 +215,13 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
||||||
</ha-button>
|
</ha-button>
|
||||||
${this.clipboard?.condition
|
${this._clipboard?.condition
|
||||||
? html` <mwc-list-item .value=${PASTE_VALUE} graphic="icon">
|
? html` <mwc-list-item .value=${PASTE_VALUE} graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.paste"
|
"ui.panel.config.automation.editor.conditions.paste"
|
||||||
)}
|
)}
|
||||||
(${this.hass.localize(
|
(${this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.conditions.type.${this.clipboard.condition.condition}.label`
|
`ui.panel.config.automation.editor.conditions.type.${this._clipboard.condition.condition}.label`
|
||||||
)})
|
)})
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiContentPaste}></ha-svg-icon
|
<ha-svg-icon slot="graphic" .path=${mdiContentPaste}></ha-svg-icon
|
||||||
></mwc-list-item>`
|
></mwc-list-item>`
|
||||||
@ -281,7 +290,9 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
|
|
||||||
let conditions: Condition[];
|
let conditions: Condition[];
|
||||||
if (value === PASTE_VALUE) {
|
if (value === PASTE_VALUE) {
|
||||||
conditions = this.conditions.concat(deepClone(this.clipboard!.condition));
|
conditions = this.conditions.concat(
|
||||||
|
deepClone(this._clipboard!.condition)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
const condition = value as Condition["condition"];
|
const condition = value as Condition["condition"];
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
import { html, LitElement } from "lit";
|
import { html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { fireEvent } from "../../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../../common/dom/fire_event";
|
||||||
import type {
|
import type { LogicalCondition } from "../../../../../data/automation";
|
||||||
LogicalCondition,
|
|
||||||
Clipboard,
|
|
||||||
} from "../../../../../data/automation";
|
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import "../ha-automation-condition";
|
import "../ha-automation-condition";
|
||||||
import type { ConditionElement } from "../ha-automation-condition-row";
|
import type { ConditionElement } from "../ha-automation-condition-row";
|
||||||
@ -19,8 +16,6 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
conditions: [],
|
conditions: [],
|
||||||
@ -35,7 +30,6 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
|||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
.clipboard=${this.clipboard}
|
|
||||||
.reOrderMode=${this.reOrderMode}
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
`;
|
`;
|
||||||
|
@ -16,12 +16,12 @@ import {
|
|||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import {
|
import {
|
||||||
css,
|
|
||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
|
||||||
LitElement,
|
LitElement,
|
||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
|
css,
|
||||||
|
html,
|
||||||
} from "lit";
|
} 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";
|
||||||
@ -46,10 +46,7 @@ import {
|
|||||||
saveAutomationConfig,
|
saveAutomationConfig,
|
||||||
showAutomationEditor,
|
showAutomationEditor,
|
||||||
triggerAutomationActions,
|
triggerAutomationActions,
|
||||||
Trigger,
|
|
||||||
Condition,
|
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import { Action } from "../../../data/script";
|
|
||||||
import { fetchEntityRegistry } from "../../../data/entity_registry";
|
import { fetchEntityRegistry } from "../../../data/entity_registry";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
@ -79,11 +76,6 @@ declare global {
|
|||||||
"ui-mode-not-available": Error;
|
"ui-mode-not-available": Error;
|
||||||
duplicate: undefined;
|
duplicate: undefined;
|
||||||
"re-order": undefined;
|
"re-order": undefined;
|
||||||
"set-clipboard": {
|
|
||||||
trigger?: Trigger;
|
|
||||||
condition?: Condition;
|
|
||||||
action?: Action;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ import { mdiHelpCircle } from "@mdi/js";
|
|||||||
import { HassEntity } from "home-assistant-js-websocket";
|
import { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
@ -11,7 +10,6 @@ import {
|
|||||||
Condition,
|
Condition,
|
||||||
ManualAutomationConfig,
|
ManualAutomationConfig,
|
||||||
Trigger,
|
Trigger,
|
||||||
Clipboard,
|
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import { Action } from "../../../data/script";
|
import { Action } from "../../../data/script";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
@ -20,7 +18,6 @@ import { documentationUrl } from "../../../util/documentation-url";
|
|||||||
import "./action/ha-automation-action";
|
import "./action/ha-automation-action";
|
||||||
import "./condition/ha-automation-condition";
|
import "./condition/ha-automation-condition";
|
||||||
import "./trigger/ha-automation-trigger";
|
import "./trigger/ha-automation-trigger";
|
||||||
import { storage } from "../../../common/decorators/storage";
|
|
||||||
|
|
||||||
@customElement("manual-automation-editor")
|
@customElement("manual-automation-editor")
|
||||||
export class HaManualAutomationEditor extends LitElement {
|
export class HaManualAutomationEditor extends LitElement {
|
||||||
@ -36,14 +33,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public stateObj?: HassEntity;
|
@property({ attribute: false }) public stateObj?: HassEntity;
|
||||||
|
|
||||||
@storage({
|
|
||||||
key: "automationClipboard",
|
|
||||||
state: true,
|
|
||||||
subscribe: false,
|
|
||||||
storage: "sessionStorage",
|
|
||||||
})
|
|
||||||
private _clipboard: Clipboard = {};
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.disabled
|
${this.disabled
|
||||||
@ -102,8 +91,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
@value-changed=${this._triggerChanged}
|
@value-changed=${this._triggerChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@set-clipboard=${this._setClipboard}
|
|
||||||
.clipboard=${this._clipboard}
|
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
@ -133,8 +120,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@set-clipboard=${this._setClipboard}
|
|
||||||
.clipboard=${this._clipboard}
|
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
@ -167,8 +152,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@set-clipboard=${this._setClipboard}
|
|
||||||
.clipboard=${this._clipboard}
|
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -180,11 +163,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setClipboard(ev: CustomEvent): void {
|
|
||||||
ev.stopPropagation();
|
|
||||||
this._clipboard = { ...this._clipboard, ...deepClone(ev.detail) };
|
|
||||||
}
|
|
||||||
|
|
||||||
private _conditionChanged(ev: CustomEvent): void {
|
private _conditionChanged(ev: CustomEvent): void {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
|
@ -3,9 +3,9 @@ import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
|||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import {
|
import {
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
|
||||||
mdiContentCopy,
|
mdiContentCopy,
|
||||||
mdiContentCut,
|
mdiContentCut,
|
||||||
|
mdiContentDuplicate,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
mdiIdentifier,
|
mdiIdentifier,
|
||||||
@ -15,9 +15,10 @@ import {
|
|||||||
mdiStopCircleOutline,
|
mdiStopCircleOutline,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { CSSResultGroup, LitElement, PropertyValues, css, html } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
import { dynamicElement } from "../../../../common/dom/dynamic-element-directive";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
||||||
@ -30,7 +31,8 @@ import "../../../../components/ha-expansion-panel";
|
|||||||
import "../../../../components/ha-icon-button";
|
import "../../../../components/ha-icon-button";
|
||||||
import "../../../../components/ha-textfield";
|
import "../../../../components/ha-textfield";
|
||||||
import { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
import { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
||||||
import { subscribeTrigger, Trigger } from "../../../../data/automation";
|
import type { AutomationClipboard } from "../../../../data/automation";
|
||||||
|
import { Trigger, subscribeTrigger } from "../../../../data/automation";
|
||||||
import { describeTrigger } from "../../../../data/automation_i18n";
|
import { describeTrigger } from "../../../../data/automation_i18n";
|
||||||
import { validateConfig } from "../../../../data/config";
|
import { validateConfig } from "../../../../data/config";
|
||||||
import { fullEntitiesContext } from "../../../../data/context";
|
import { fullEntitiesContext } from "../../../../data/context";
|
||||||
@ -110,6 +112,14 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
|
|
||||||
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
@query("ha-yaml-editor") private _yamlEditor?: HaYamlEditor;
|
||||||
|
|
||||||
|
@storage({
|
||||||
|
key: "automationClipboard",
|
||||||
|
state: false,
|
||||||
|
subscribe: true,
|
||||||
|
storage: "sessionStorage",
|
||||||
|
})
|
||||||
|
public _clipboard?: AutomationClipboard;
|
||||||
|
|
||||||
@state()
|
@state()
|
||||||
@consume({ context: fullEntitiesContext, subscribe: true })
|
@consume({ context: fullEntitiesContext, subscribe: true })
|
||||||
_entityReg!: EntityRegistryEntry[];
|
_entityReg!: EntityRegistryEntry[];
|
||||||
@ -469,10 +479,10 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
fireEvent(this, "duplicate");
|
fireEvent(this, "duplicate");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
fireEvent(this, "set-clipboard", { trigger: this.trigger });
|
this._setClipboard();
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
fireEvent(this, "set-clipboard", { trigger: this.trigger });
|
this._setClipboard();
|
||||||
fireEvent(this, "value-changed", { value: null });
|
fireEvent(this, "value-changed", { value: null });
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
@ -492,6 +502,13 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _setClipboard() {
|
||||||
|
this._clipboard = {
|
||||||
|
...this._clipboard,
|
||||||
|
trigger: this.trigger,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private _onDelete() {
|
private _onDelete() {
|
||||||
showConfirmationDialog(this, {
|
showConfirmationDialog(this, {
|
||||||
title: this.hass.localize(
|
title: this.hass.localize(
|
||||||
|
@ -27,7 +27,7 @@ import "../../../../components/ha-button-menu";
|
|||||||
import "../../../../components/ha-button";
|
import "../../../../components/ha-button";
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
import "../../../../components/ha-svg-icon";
|
import "../../../../components/ha-svg-icon";
|
||||||
import { Trigger, Clipboard } from "../../../../data/automation";
|
import { Trigger, AutomationClipboard } from "../../../../data/automation";
|
||||||
import { TRIGGER_TYPES } from "../../../../data/trigger";
|
import { TRIGGER_TYPES } from "../../../../data/trigger";
|
||||||
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
import { SortableInstance } from "../../../../resources/sortable";
|
import { SortableInstance } from "../../../../resources/sortable";
|
||||||
@ -51,6 +51,7 @@ import "./types/ha-automation-trigger-time";
|
|||||||
import "./types/ha-automation-trigger-time_pattern";
|
import "./types/ha-automation-trigger-time_pattern";
|
||||||
import "./types/ha-automation-trigger-webhook";
|
import "./types/ha-automation-trigger-webhook";
|
||||||
import "./types/ha-automation-trigger-zone";
|
import "./types/ha-automation-trigger-zone";
|
||||||
|
import { storage } from "../../../../common/decorators/storage";
|
||||||
|
|
||||||
const PASTE_VALUE = "__paste__";
|
const PASTE_VALUE = "__paste__";
|
||||||
|
|
||||||
@ -66,7 +67,13 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public reOrderMode = false;
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@property() public clipboard?: Clipboard;
|
@storage({
|
||||||
|
key: "automationClipboard",
|
||||||
|
state: true,
|
||||||
|
subscribe: true,
|
||||||
|
storage: "sessionStorage",
|
||||||
|
})
|
||||||
|
public _clipboard?: AutomationClipboard;
|
||||||
|
|
||||||
private _focusLastTriggerOnChange = false;
|
private _focusLastTriggerOnChange = false;
|
||||||
|
|
||||||
@ -155,13 +162,13 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
||||||
</ha-button>
|
</ha-button>
|
||||||
${this.clipboard?.trigger
|
${this._clipboard?.trigger
|
||||||
? html` <mwc-list-item .value=${PASTE_VALUE} graphic="icon">
|
? html` <mwc-list-item .value=${PASTE_VALUE} graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.paste"
|
"ui.panel.config.automation.editor.triggers.paste"
|
||||||
)}
|
)}
|
||||||
(${this.hass.localize(
|
(${this.hass.localize(
|
||||||
`ui.panel.config.automation.editor.triggers.type.${this.clipboard.trigger.platform}.label`
|
`ui.panel.config.automation.editor.triggers.type.${this._clipboard.trigger.platform}.label`
|
||||||
)})
|
)})
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
@ -259,7 +266,7 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
|
|
||||||
let triggers: Trigger[];
|
let triggers: Trigger[];
|
||||||
if (value === PASTE_VALUE) {
|
if (value === PASTE_VALUE) {
|
||||||
triggers = this.triggers.concat(deepClone(this.clipboard!.trigger));
|
triggers = this.triggers.concat(deepClone(this._clipboard!.trigger));
|
||||||
} else {
|
} else {
|
||||||
const platform = value as Trigger["platform"];
|
const platform = value as Trigger["platform"];
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import { mdiHelpCircle } from "@mdi/js";
|
import { mdiHelpCircle } from "@mdi/js";
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { storage } from "../../../common/decorators/storage";
|
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
import { Clipboard } from "../../../data/automation";
|
|
||||||
import { Action, ScriptConfig } from "../../../data/script";
|
import { Action, ScriptConfig } from "../../../data/script";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
@ -26,14 +23,6 @@ export class HaManualScriptEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public config!: ScriptConfig;
|
@property({ attribute: false }) public config!: ScriptConfig;
|
||||||
|
|
||||||
@storage({
|
|
||||||
key: "automationClipboard",
|
|
||||||
state: true,
|
|
||||||
subscribe: false,
|
|
||||||
storage: "sessionStorage",
|
|
||||||
})
|
|
||||||
private _clipboard: Clipboard = {};
|
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${this.disabled
|
${this.disabled
|
||||||
@ -70,8 +59,6 @@ export class HaManualScriptEditor extends LitElement {
|
|||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
@set-clipboard=${this._setClipboard}
|
|
||||||
.clipboard=${this._clipboard}
|
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@ -83,11 +70,6 @@ export class HaManualScriptEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _setClipboard(ev: CustomEvent): void {
|
|
||||||
ev.stopPropagation();
|
|
||||||
this._clipboard = { ...this._clipboard, ...deepClone(ev.detail) };
|
|
||||||
}
|
|
||||||
|
|
||||||
private _duplicate() {
|
private _duplicate() {
|
||||||
fireEvent(this, "duplicate");
|
fireEvent(this, "duplicate");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user