mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
20220905.0 (#13604)
This commit is contained in:
commit
abbfde19a2
56
gallery/src/pages/Text/remove-delete-add-create.markdown
Normal file
56
gallery/src/pages/Text/remove-delete-add-create.markdown
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
---
|
||||||
|
title: When to use remove, delete, add and create
|
||||||
|
subtitle: The difference between remove/delete and add/create.
|
||||||
|
---
|
||||||
|
|
||||||
|
# Remove vs Delete
|
||||||
|
Remove and Delete are quite similar, but can be frustrating if used inconsistently.
|
||||||
|
|
||||||
|
## Remove
|
||||||
|
Take away and set aside, but kept in existence.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
* Removing a user's permission
|
||||||
|
* Removing a user from a group
|
||||||
|
* Removing links between items
|
||||||
|
* Removing a widget
|
||||||
|
* Removing a link
|
||||||
|
* Removing an item from a cart
|
||||||
|
|
||||||
|
## Delete
|
||||||
|
Erase, rendered nonexistent or nonrecoverable.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
* Deleting a field
|
||||||
|
* Deleting a value in a field
|
||||||
|
* Deleting a task
|
||||||
|
* Deleting a group
|
||||||
|
* Deleting a permission
|
||||||
|
* Deleting a calendar event
|
||||||
|
|
||||||
|
# Add vs Create
|
||||||
|
In most cases, Create can be paired with Delete, and Add can be paired with Remove.
|
||||||
|
|
||||||
|
## Add
|
||||||
|
An already-exisiting item.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
* Adding a permission to a user
|
||||||
|
* Adding a user to a group
|
||||||
|
* Adding links between items
|
||||||
|
* Adding a widget
|
||||||
|
* Adding a link
|
||||||
|
* Adding an item to a cart
|
||||||
|
|
||||||
|
## Create
|
||||||
|
Something made from scratch.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
* Creating a new field
|
||||||
|
* Creating a new value in a field
|
||||||
|
* Creating a new task
|
||||||
|
* Creating a new group
|
||||||
|
* Creating a new permission
|
||||||
|
* Creating a new calendar event
|
||||||
|
|
||||||
|
Based on this is [UX magazine article](https://uxmag.com/articles/ui-copy-remove-vs-delete2-banner).
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
title: Dialgos
|
title: Dialogs
|
||||||
subtitle: Dialogs provide important prompts in a user flow.
|
subtitle: Dialogs provide important prompts in a user flow.
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "home-assistant-frontend"
|
name = "home-assistant-frontend"
|
||||||
version = "20220902.0"
|
version = "20220905.0"
|
||||||
license = {text = "Apache-2.0"}
|
license = {text = "Apache-2.0"}
|
||||||
description = "The Home Assistant frontend"
|
description = "The Home Assistant frontend"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -2,17 +2,18 @@ import { HassEntity } from "home-assistant-js-websocket";
|
|||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
||||||
import { FrontendLocaleData } from "../../data/translation";
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
import {
|
import {
|
||||||
UPDATE_SUPPORT_PROGRESS,
|
|
||||||
updateIsInstallingFromAttributes,
|
updateIsInstallingFromAttributes,
|
||||||
|
UPDATE_SUPPORT_PROGRESS,
|
||||||
} from "../../data/update";
|
} from "../../data/update";
|
||||||
|
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
||||||
import { formatDate } from "../datetime/format_date";
|
import { formatDate } from "../datetime/format_date";
|
||||||
import { formatDateTime } from "../datetime/format_date_time";
|
import { formatDateTime } from "../datetime/format_date_time";
|
||||||
import { formatTime } from "../datetime/format_time";
|
import { formatTime } from "../datetime/format_time";
|
||||||
import { formatNumber, isNumericFromAttributes } from "../number/format_number";
|
import { formatNumber, isNumericFromAttributes } from "../number/format_number";
|
||||||
|
import { blankBeforePercent } from "../translations/blank_before_percent";
|
||||||
import { LocalizeFunc } from "../translations/localize";
|
import { LocalizeFunc } from "../translations/localize";
|
||||||
import { supportsFeatureFromAttributes } from "./supports-feature";
|
|
||||||
import { formatDuration, UNIT_TO_SECOND_CONVERT } from "../datetime/duration";
|
|
||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
import { supportsFeatureFromAttributes } from "./supports-feature";
|
||||||
|
|
||||||
export const computeStateDisplay = (
|
export const computeStateDisplay = (
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
@ -67,7 +68,7 @@ export const computeStateDisplayFromEntityAttributes = (
|
|||||||
const unit = !attributes.unit_of_measurement
|
const unit = !attributes.unit_of_measurement
|
||||||
? ""
|
? ""
|
||||||
: attributes.unit_of_measurement === "%"
|
: attributes.unit_of_measurement === "%"
|
||||||
? "%"
|
? blankBeforePercent(locale) + "%"
|
||||||
: ` ${attributes.unit_of_measurement}`;
|
: ` ${attributes.unit_of_measurement}`;
|
||||||
return `${formatNumber(state, locale)}${unit}`;
|
return `${formatNumber(state, locale)}${unit}`;
|
||||||
}
|
}
|
||||||
|
18
src/common/translations/blank_before_percent.ts
Normal file
18
src/common/translations/blank_before_percent.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { FrontendLocaleData } from "../../data/translation";
|
||||||
|
|
||||||
|
// Logic based on https://en.wikipedia.org/wiki/Percent_sign#Form_and_spacing
|
||||||
|
export const blankBeforePercent = (
|
||||||
|
localeOptions: FrontendLocaleData
|
||||||
|
): string => {
|
||||||
|
switch (localeOptions.language) {
|
||||||
|
case "cz":
|
||||||
|
case "de":
|
||||||
|
case "fi":
|
||||||
|
case "fr":
|
||||||
|
case "sk":
|
||||||
|
case "sv":
|
||||||
|
return " ";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
};
|
@ -2,6 +2,7 @@ import { css, LitElement, PropertyValues, svg, TemplateResult } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { styleMap } from "lit/directives/style-map";
|
import { styleMap } from "lit/directives/style-map";
|
||||||
import { formatNumber } from "../common/number/format_number";
|
import { formatNumber } from "../common/number/format_number";
|
||||||
|
import { blankBeforePercent } from "../common/translations/blank_before_percent";
|
||||||
import { afterNextRender } from "../common/util/render-status";
|
import { afterNextRender } from "../common/util/render-status";
|
||||||
import { FrontendLocaleData } from "../data/translation";
|
import { FrontendLocaleData } from "../data/translation";
|
||||||
import { getValueInPercentage, normalize } from "../util/calculate";
|
import { getValueInPercentage, normalize } from "../util/calculate";
|
||||||
@ -133,7 +134,11 @@ export class Gauge extends LitElement {
|
|||||||
? this._segment_label
|
? this._segment_label
|
||||||
: this.valueText || formatNumber(this.value, this.locale)
|
: this.valueText || formatNumber(this.value, this.locale)
|
||||||
}${
|
}${
|
||||||
this._segment_label ? "" : this.label === "%" ? "%" : ` ${this.label}`
|
this._segment_label
|
||||||
|
? ""
|
||||||
|
: this.label === "%"
|
||||||
|
? blankBeforePercent(this.locale) + "%"
|
||||||
|
: ` ${this.label}`
|
||||||
}
|
}
|
||||||
</text>
|
</text>
|
||||||
</svg>`;
|
</svg>`;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { css, html, LitElement, TemplateResult } from "lit";
|
import { css, html, LitElement, PropertyValues, TemplateResult } from "lit";
|
||||||
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
import { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
@ -123,6 +123,10 @@ export class HaIconPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected shouldUpdate(changedProps: PropertyValues) {
|
||||||
|
return !this._opened || changedProps.has("_opened");
|
||||||
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
private _valueChanged(ev: PolymerChangedEvent<string>) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this._setValue(ev.detail.value);
|
this._setValue(ev.detail.value);
|
||||||
|
@ -9,6 +9,7 @@ import { DeviceCondition, DeviceTrigger } from "./device_automation";
|
|||||||
import { Action, MODES } from "./script";
|
import { Action, MODES } from "./script";
|
||||||
|
|
||||||
export const AUTOMATION_DEFAULT_MODE: typeof MODES[number] = "single";
|
export const AUTOMATION_DEFAULT_MODE: typeof MODES[number] = "single";
|
||||||
|
export const AUTOMATION_DEFAULT_MAX = 10;
|
||||||
|
|
||||||
export interface AutomationEntity extends HassEntityBase {
|
export interface AutomationEntity extends HassEntityBase {
|
||||||
attributes: HassEntityAttributeBase & {
|
attributes: HassEntityAttributeBase & {
|
||||||
|
@ -51,6 +51,7 @@ interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
|||||||
media_duration?: number;
|
media_duration?: number;
|
||||||
media_position?: number;
|
media_position?: number;
|
||||||
media_title?: string;
|
media_title?: string;
|
||||||
|
media_channel?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
entity_picture_local?: string;
|
entity_picture_local?: string;
|
||||||
is_volume_muted?: boolean;
|
is_volume_muted?: boolean;
|
||||||
@ -235,6 +236,9 @@ export const computeMediaDescription = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "channel":
|
||||||
|
secondaryTitle = stateObj.attributes.media_channel!;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
secondaryTitle = stateObj.attributes.app_name || "";
|
secondaryTitle = stateObj.attributes.app_name || "";
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,8 @@ class MoreInfoMediaPlayer extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
${supportsFeature(stateObj, SUPPORT_SELECT_SOUND_MODE) &&
|
${![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) &&
|
||||||
|
supportsFeature(stateObj, SUPPORT_SELECT_SOUND_MODE) &&
|
||||||
stateObj.attributes.sound_mode_list?.length
|
stateObj.attributes.sound_mode_list?.length
|
||||||
? html`
|
? html`
|
||||||
<div class="sound-input">
|
<div class="sound-input">
|
||||||
|
@ -45,13 +45,14 @@ import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box
|
|||||||
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import "../../logbook/ha-logbook";
|
import "../../logbook/ha-logbook";
|
||||||
import { configSections } from "../ha-panel-config";
|
|
||||||
import {
|
import {
|
||||||
loadAreaRegistryDetailDialog,
|
loadAreaRegistryDetailDialog,
|
||||||
showAreaRegistryDetailDialog,
|
showAreaRegistryDetailDialog,
|
||||||
} from "./show-dialog-area-registry-detail";
|
} from "./show-dialog-area-registry-detail";
|
||||||
|
import "../../../layouts/hass-error-screen";
|
||||||
|
import "../../../layouts/hass-subpage";
|
||||||
|
|
||||||
declare type NameAndEntity<EntityType extends HassEntity> = {
|
declare type NameAndEntity<EntityType extends HassEntity> = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -66,11 +67,9 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
||||||
|
|
||||||
@property() public isWide!: boolean;
|
@property({ type: Boolean }) public isWide!: boolean;
|
||||||
|
|
||||||
@property() public showAdvanced!: boolean;
|
@property({ type: Boolean }) public showAdvanced!: boolean;
|
||||||
|
|
||||||
@property() public route!: Route;
|
|
||||||
|
|
||||||
@state() public _areas!: AreaRegistryEntry[];
|
@state() public _areas!: AreaRegistryEntry[];
|
||||||
|
|
||||||
@ -242,43 +241,20 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.tabs=${configSections.areas}
|
.header=${area.name}
|
||||||
.route=${this.route}
|
|
||||||
>
|
>
|
||||||
${this.narrow
|
<ha-icon-button
|
||||||
? html`<span slot="header"> ${area.name} </span>
|
.path=${mdiPencil}
|
||||||
<ha-icon-button
|
.entry=${area}
|
||||||
.path=${mdiPencil}
|
@click=${this._showSettings}
|
||||||
.entry=${area}
|
slot="toolbar-icon"
|
||||||
@click=${this._showSettings}
|
.label=${this.hass.localize("ui.panel.config.areas.edit_settings")}
|
||||||
slot="toolbar-icon"
|
></ha-icon-button>
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.areas.edit_settings"
|
|
||||||
)}
|
|
||||||
></ha-icon-button>`
|
|
||||||
: ""}
|
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
${!this.narrow
|
|
||||||
? html`
|
|
||||||
<div class="fullwidth">
|
|
||||||
<h1>
|
|
||||||
${area.name}
|
|
||||||
<ha-icon-button
|
|
||||||
.path=${mdiPencil}
|
|
||||||
.entry=${area}
|
|
||||||
@click=${this._showSettings}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.areas.edit_settings"
|
|
||||||
)}
|
|
||||||
></ha-icon-button>
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
<div class="column">
|
<div class="column">
|
||||||
${area.picture
|
${area.picture
|
||||||
? html`<div class="img-container">
|
? html`<div class="img-container">
|
||||||
@ -504,7 +480,7 @@ class HaConfigAreaPage extends SubscribeMixin(LitElement) {
|
|||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</hass-tabs-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import { ActionDetail } from "@material/mwc-list/mwc-list-foundation";
|
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 {
|
||||||
mdiArrowDown,
|
|
||||||
mdiArrowUp,
|
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
mdiContentDuplicate,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
@ -17,13 +15,15 @@ import { customElement, property, query, state } from "lit/decorators";
|
|||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
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 { handleStructError } from "../../../../common/structs/handle-errors";
|
import { handleStructError } from "../../../../common/structs/handle-errors";
|
||||||
import "../../../../components/ha-alert";
|
import "../../../../components/ha-alert";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
import "../../../../components/ha-card";
|
import "../../../../components/ha-card";
|
||||||
import "../../../../components/ha-icon-button";
|
|
||||||
import "../../../../components/ha-expansion-panel";
|
import "../../../../components/ha-expansion-panel";
|
||||||
|
import "../../../../components/ha-icon-button";
|
||||||
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
import type { HaYamlEditor } from "../../../../components/ha-yaml-editor";
|
||||||
|
import { ACTION_TYPES } from "../../../../data/action";
|
||||||
import { validateConfig } from "../../../../data/config";
|
import { validateConfig } from "../../../../data/config";
|
||||||
import { Action, getActionType } from "../../../../data/script";
|
import { Action, getActionType } from "../../../../data/script";
|
||||||
import { describeAction } from "../../../../data/script_i18n";
|
import { describeAction } from "../../../../data/script_i18n";
|
||||||
@ -50,8 +50,6 @@ 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 { ACTION_TYPES } from "../../../../data/action";
|
|
||||||
import { capitalizeFirstLetter } from "../../../../common/string/capitalize-first-letter";
|
|
||||||
|
|
||||||
const getType = (action: Action | undefined) => {
|
const getType = (action: Action | undefined) => {
|
||||||
if (!action) {
|
if (!action) {
|
||||||
@ -66,13 +64,6 @@ const getType = (action: Action | undefined) => {
|
|||||||
return Object.keys(ACTION_TYPES).find((option) => option in action);
|
return Object.keys(ACTION_TYPES).find((option) => option in action);
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
|
||||||
// for fire event
|
|
||||||
interface HASSDomEvents {
|
|
||||||
"move-action": { direction: "up" | "down" };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ActionElement extends LitElement {
|
export interface ActionElement extends LitElement {
|
||||||
action: Action;
|
action: Action;
|
||||||
}
|
}
|
||||||
@ -107,12 +98,12 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
|
|
||||||
@property() public action!: Action;
|
@property() public action!: Action;
|
||||||
|
|
||||||
@property() public index!: number;
|
|
||||||
|
|
||||||
@property() public totalActions!: number;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public narrow = false;
|
@property({ type: Boolean }) public narrow = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public hideMenu = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@state() private _uiModeAvailable = true;
|
@state() private _uiModeAvailable = true;
|
||||||
@ -165,119 +156,112 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
${capitalizeFirstLetter(describeAction(this.hass, this.action))}
|
${capitalizeFirstLetter(describeAction(this.hass, this.action))}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
${this.index !== 0
|
<slot name="icons" slot="icons"></slot>
|
||||||
? html`
|
${this.hideMenu
|
||||||
<ha-icon-button
|
? ""
|
||||||
|
: html`
|
||||||
|
<ha-button-menu
|
||||||
slot="icons"
|
slot="icons"
|
||||||
.label=${this.hass.localize(
|
fixed
|
||||||
"ui.panel.config.automation.editor.move_up"
|
corner="BOTTOM_START"
|
||||||
)}
|
@action=${this._handleAction}
|
||||||
.path=${mdiArrowUp}
|
@click=${preventDefault}
|
||||||
@click=${this._moveUp}
|
>
|
||||||
></ha-icon-button>
|
<ha-icon-button
|
||||||
`
|
slot="trigger"
|
||||||
: ""}
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
${this.index !== this.totalActions - 1
|
.path=${mdiDotsVertical}
|
||||||
? html`
|
></ha-icon-button>
|
||||||
<ha-icon-button
|
<mwc-list-item graphic="icon">
|
||||||
slot="icons"
|
${this.hass.localize(
|
||||||
.label=${this.hass.localize(
|
"ui.panel.config.automation.editor.actions.run"
|
||||||
"ui.panel.config.automation.editor.move_down"
|
)}
|
||||||
)}
|
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
||||||
.path=${mdiArrowDown}
|
</mwc-list-item>
|
||||||
@click=${this._moveDown}
|
|
||||||
></ha-icon-button>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
<ha-button-menu
|
|
||||||
slot="icons"
|
|
||||||
fixed
|
|
||||||
corner="BOTTOM_START"
|
|
||||||
@action=${this._handleAction}
|
|
||||||
@click=${preventDefault}
|
|
||||||
>
|
|
||||||
<ha-icon-button
|
|
||||||
slot="trigger"
|
|
||||||
.label=${this.hass.localize("ui.common.menu")}
|
|
||||||
.path=${mdiDotsVertical}
|
|
||||||
></ha-icon-button>
|
|
||||||
<mwc-list-item graphic="icon">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.run"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.rename"
|
"ui.panel.config.automation.editor.actions.rename"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
<mwc-list-item graphic="icon">
|
.path=${mdiRenameBox}
|
||||||
${this.hass.localize(
|
></ha-svg-icon>
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
</mwc-list-item>
|
||||||
)}
|
<mwc-list-item graphic="icon">
|
||||||
<ha-svg-icon
|
${this.hass.localize(
|
||||||
slot="graphic"
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
.path=${mdiContentDuplicate}
|
)}
|
||||||
></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!this._uiModeAvailable} graphic="icon">
|
<mwc-list-item
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
.disabled=${!this._uiModeAvailable}
|
||||||
${!yamlMode
|
graphic="icon"
|
||||||
? html`<ha-svg-icon
|
>
|
||||||
class="selected_menu_item"
|
${this.hass.localize(
|
||||||
slot="graphic"
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
.path=${mdiCheck}
|
)}
|
||||||
></ha-svg-icon>`
|
${!yamlMode
|
||||||
: ``}
|
? html`<ha-svg-icon
|
||||||
</mwc-list-item>
|
class="selected_menu_item"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiCheck}
|
||||||
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!this._uiModeAvailable} graphic="icon">
|
<mwc-list-item
|
||||||
${this.hass.localize(
|
.disabled=${!this._uiModeAvailable}
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
graphic="icon"
|
||||||
)}
|
>
|
||||||
${yamlMode
|
${this.hass.localize(
|
||||||
? html`<ha-svg-icon
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
class="selected_menu_item"
|
)}
|
||||||
slot="graphic"
|
${yamlMode
|
||||||
.path=${mdiCheck}
|
? html`<ha-svg-icon
|
||||||
></ha-svg-icon>`
|
class="selected_menu_item"
|
||||||
: ``}
|
slot="graphic"
|
||||||
</mwc-list-item>
|
.path=${mdiCheck}
|
||||||
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.action.enabled === false
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.enable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.disable"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${this.action.enabled === false
|
||||||
|
? mdiPlayCircleOutline
|
||||||
|
: mdiStopCircleOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
<mwc-list-item class="warning" graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.delete"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
class="warning"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
</ha-button-menu>
|
||||||
|
`}
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
|
||||||
${this.action.enabled === false
|
|
||||||
? this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.enable"
|
|
||||||
)
|
|
||||||
: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.disable"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
|
||||||
slot="graphic"
|
|
||||||
.path=${this.action.enabled === false
|
|
||||||
? mdiPlayCircleOutline
|
|
||||||
: mdiStopCircleOutline}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
<mwc-list-item class="warning" graphic="icon">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.delete"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
|
||||||
class="warning"
|
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiDelete}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
</ha-button-menu>
|
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
"card-content": true,
|
"card-content": true,
|
||||||
@ -327,6 +311,7 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
hass: this.hass,
|
hass: this.hass,
|
||||||
action: this.action,
|
action: this.action,
|
||||||
narrow: this.narrow,
|
narrow: this.narrow,
|
||||||
|
reOrderMode: this.reOrderMode,
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
@ -346,16 +331,6 @@ export default class HaAutomationActionRow extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _moveUp(ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
fireEvent(this, "move-action", { direction: "up" });
|
|
||||||
}
|
|
||||||
|
|
||||||
private _moveDown(ev) {
|
|
||||||
ev.preventDefault();
|
|
||||||
fireEvent(this, "move-action", { direction: "down" });
|
|
||||||
}
|
|
||||||
|
|
||||||
private async _handleAction(ev: CustomEvent<ActionDetail>) {
|
private async _handleAction(ev: CustomEvent<ActionDetail>) {
|
||||||
switch (ev.detail.index) {
|
switch (ev.detail.index) {
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import { mdiPlus } from "@mdi/js";
|
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
import type { ActionDetail } from "@material/mwc-list";
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
import memoizeOne from "memoize-one";
|
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
||||||
|
import deepClone from "deep-clone-simple";
|
||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { repeat } from "lit/directives/repeat";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import type { SortableEvent } from "sortablejs";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-svg-icon";
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
|
import { ACTION_TYPES } from "../../../../data/action";
|
||||||
import { Action } from "../../../../data/script";
|
import { Action } from "../../../../data/script";
|
||||||
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
|
import {
|
||||||
|
loadSortable,
|
||||||
|
SortableInstance,
|
||||||
|
} from "../../../../resources/sortable.ondemand";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-action-row";
|
import "./ha-automation-action-row";
|
||||||
import type HaAutomationActionRow from "./ha-automation-action-row";
|
import type HaAutomationActionRow from "./ha-automation-action-row";
|
||||||
@ -27,10 +37,6 @@ 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 { ACTION_TYPES } from "../../../../data/action";
|
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
|
||||||
import { LocalizeFunc } from "../../../../common/translations/localize";
|
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
|
||||||
|
|
||||||
@customElement("ha-automation-action")
|
@customElement("ha-automation-action")
|
||||||
export default class HaAutomationAction extends LitElement {
|
export default class HaAutomationAction extends LitElement {
|
||||||
@ -40,28 +46,62 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
|
|
||||||
@property() public actions!: Action[];
|
@property() public actions!: Action[];
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _focusLastActionOnChange = false;
|
private _focusLastActionOnChange = false;
|
||||||
|
|
||||||
private _actionKeys = new WeakMap<Action, string>();
|
private _actionKeys = new WeakMap<Action, string>();
|
||||||
|
|
||||||
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${repeat(
|
<div class="actions">
|
||||||
this.actions,
|
${repeat(
|
||||||
(action) => this._getKey(action),
|
this.actions,
|
||||||
(action, idx) => html`
|
(action) => this._getKey(action),
|
||||||
<ha-automation-action-row
|
(action, idx) => html`
|
||||||
.index=${idx}
|
<ha-automation-action-row
|
||||||
.totalActions=${this.actions.length}
|
.index=${idx}
|
||||||
.action=${action}
|
.action=${action}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
@duplicate=${this._duplicateAction}
|
.hideMenu=${this.reOrderMode}
|
||||||
@move-action=${this._move}
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._actionChanged}
|
@duplicate=${this._duplicateAction}
|
||||||
.hass=${this.hass}
|
@value-changed=${this._actionChanged}
|
||||||
></ha-automation-action-row>
|
.hass=${this.hass}
|
||||||
`
|
>
|
||||||
)}
|
${this.reOrderMode
|
||||||
|
? html`
|
||||||
|
<ha-icon-button
|
||||||
|
.index=${idx}
|
||||||
|
slot="icons"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.move_up"
|
||||||
|
)}
|
||||||
|
.path=${mdiArrowUp}
|
||||||
|
@click=${this._moveUp}
|
||||||
|
.disabled=${idx === 0}
|
||||||
|
></ha-icon-button>
|
||||||
|
<ha-icon-button
|
||||||
|
.index=${idx}
|
||||||
|
slot="icons"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.move_down"
|
||||||
|
)}
|
||||||
|
.path=${mdiArrowDown}
|
||||||
|
@click=${this._moveDown}
|
||||||
|
.disabled=${idx === this.actions.length - 1}
|
||||||
|
></ha-icon-button>
|
||||||
|
<div class="handle" slot="icons">
|
||||||
|
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</ha-automation-action-row>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<ha-button-menu fixed @action=${this._addAction}>
|
<ha-button-menu fixed @action=${this._addAction}>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@ -86,6 +126,13 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
|
|
||||||
|
if (changedProps.has("reOrderMode")) {
|
||||||
|
if (this.reOrderMode) {
|
||||||
|
this._createSortable();
|
||||||
|
} else {
|
||||||
|
this._destroySortable();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (changedProps.has("actions") && this._focusLastActionOnChange) {
|
if (changedProps.has("actions") && this._focusLastActionOnChange) {
|
||||||
this._focusLastActionOnChange = false;
|
this._focusLastActionOnChange = false;
|
||||||
|
|
||||||
@ -100,6 +147,33 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _createSortable() {
|
||||||
|
const Sortable = await loadSortable();
|
||||||
|
this._sortable = new Sortable(this.shadowRoot!.querySelector(".actions")!, {
|
||||||
|
animation: 150,
|
||||||
|
fallbackClass: "sortable-fallback",
|
||||||
|
handle: ".handle",
|
||||||
|
onChoose: (evt: SortableEvent) => {
|
||||||
|
(evt.item as any).placeholder =
|
||||||
|
document.createComment("sort-placeholder");
|
||||||
|
evt.item.after((evt.item as any).placeholder);
|
||||||
|
},
|
||||||
|
onEnd: (evt: SortableEvent) => {
|
||||||
|
// put back in original location
|
||||||
|
if ((evt.item as any).placeholder) {
|
||||||
|
(evt.item as any).placeholder.replaceWith(evt.item);
|
||||||
|
delete (evt.item as any).placeholder;
|
||||||
|
}
|
||||||
|
this._dragged(evt);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _destroySortable() {
|
||||||
|
this._sortable?.destroy();
|
||||||
|
this._sortable = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private _getKey(action: Action) {
|
private _getKey(action: Action) {
|
||||||
if (!this._actionKeys.has(action)) {
|
if (!this._actionKeys.has(action)) {
|
||||||
this._actionKeys.set(action, Math.random().toString());
|
this._actionKeys.set(action, Math.random().toString());
|
||||||
@ -121,12 +195,24 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: actions });
|
fireEvent(this, "value-changed", { value: actions });
|
||||||
}
|
}
|
||||||
|
|
||||||
private _move(ev: CustomEvent) {
|
private _moveUp(ev) {
|
||||||
// Prevent possible parent action-row from also moving
|
|
||||||
ev.stopPropagation();
|
|
||||||
|
|
||||||
const index = (ev.target as any).index;
|
const index = (ev.target as any).index;
|
||||||
const newIndex = ev.detail.direction === "up" ? index - 1 : index + 1;
|
const newIndex = index - 1;
|
||||||
|
this._move(index, newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _moveDown(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = index + 1;
|
||||||
|
this._move(index, newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _dragged(ev: SortableEvent): void {
|
||||||
|
if (ev.oldIndex === ev.newIndex) return;
|
||||||
|
this._move(ev.oldIndex!, ev.newIndex!);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _move(index: number, newIndex: number) {
|
||||||
const actions = this.actions.concat();
|
const actions = this.actions.concat();
|
||||||
const action = actions.splice(index, 1)[0];
|
const action = actions.splice(index, 1)[0];
|
||||||
actions.splice(newIndex, 0, action);
|
actions.splice(newIndex, 0, action);
|
||||||
@ -177,16 +263,27 @@ export default class HaAutomationAction extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return [
|
||||||
ha-automation-action-row {
|
sortableStyles,
|
||||||
display: block;
|
css`
|
||||||
margin-bottom: 16px;
|
ha-automation-action-row {
|
||||||
scroll-margin-top: 48px;
|
display: block;
|
||||||
}
|
margin-bottom: 16px;
|
||||||
ha-svg-icon {
|
scroll-margin-top: 48px;
|
||||||
height: 20px;
|
}
|
||||||
}
|
ha-svg-icon {
|
||||||
`;
|
height: 20px;
|
||||||
|
}
|
||||||
|
.handle {
|
||||||
|
cursor: move;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
.handle ha-svg-icon {
|
||||||
|
pointer-events: none;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,8 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property() public action!: ChooseAction;
|
@property() public action!: ChooseAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _showDefault = false;
|
@state() private _showDefault = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
@ -52,6 +54,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-condition
|
<ha-automation-condition
|
||||||
.conditions=${option.conditions}
|
.conditions=${option.conditions}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.idx=${idx}
|
.idx=${idx}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
@ -89,6 +92,7 @@ export class HaChooseAction extends LitElement implements ActionElement {
|
|||||||
</h2>
|
</h2>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.default || []}
|
.actions=${action.default || []}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._defaultChanged}
|
@value-changed=${this._defaultChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
@ -15,6 +15,8 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: IfAction;
|
@property({ attribute: false }) public action!: IfAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _showElse = false;
|
@state() private _showElse = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
@ -35,8 +37,9 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-condition
|
<ha-automation-condition
|
||||||
.conditions=${action.if}
|
.conditions=${action.if}
|
||||||
.hass=${this.hass}
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._ifChanged}
|
@value-changed=${this._ifChanged}
|
||||||
|
.hass=${this.hass}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
|
|
||||||
<h3>
|
<h3>
|
||||||
@ -46,6 +49,7 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.then}
|
.actions=${action.then}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._thenChanged}
|
@value-changed=${this._thenChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
@ -58,6 +62,7 @@ export class HaIfAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.else || []}
|
.actions=${action.else || []}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._elseChanged}
|
@value-changed=${this._elseChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
@ -14,6 +14,8 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: ParallelAction;
|
@property({ attribute: false }) public action!: ParallelAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
parallel: [],
|
parallel: [],
|
||||||
@ -26,6 +28,7 @@ export class HaParallelAction extends LitElement implements ActionElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.parallel}
|
.actions=${action.parallel}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._actionsChanged}
|
@value-changed=${this._actionsChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
@ -25,6 +25,8 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public action!: RepeatAction;
|
@property({ attribute: false }) public action!: RepeatAction;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return { repeat: { count: 2, sequence: [] } };
|
return { repeat: { count: 2, sequence: [] } };
|
||||||
}
|
}
|
||||||
@ -95,6 +97,7 @@ export class HaRepeatAction extends LitElement implements ActionElement {
|
|||||||
</h3>
|
</h3>
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
.actions=${action.sequence}
|
.actions=${action.sequence}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
|
@ -0,0 +1,167 @@
|
|||||||
|
import "@material/mwc-button";
|
||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
|
import "../../../../components/ha-textfield";
|
||||||
|
import "../../../../components/ha-select";
|
||||||
|
import { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||||
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../../../../types";
|
||||||
|
import type { AutomationModeDialog } from "./show-dialog-automation-mode";
|
||||||
|
import {
|
||||||
|
AUTOMATION_DEFAULT_MAX,
|
||||||
|
AUTOMATION_DEFAULT_MODE,
|
||||||
|
} from "../../../../data/automation";
|
||||||
|
import { documentationUrl } from "../../../../util/documentation-url";
|
||||||
|
import { isMaxMode, MODES } from "../../../../data/script";
|
||||||
|
import "@material/mwc-list/mwc-list-item";
|
||||||
|
import { stopPropagation } from "../../../../common/dom/stop_propagation";
|
||||||
|
|
||||||
|
@customElement("ha-dialog-automation-mode")
|
||||||
|
class DialogAutomationMode extends LitElement implements HassDialog {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@state() private _opened = false;
|
||||||
|
|
||||||
|
private _params!: AutomationModeDialog;
|
||||||
|
|
||||||
|
@state() private _newMode: typeof MODES[number] = AUTOMATION_DEFAULT_MODE;
|
||||||
|
|
||||||
|
@state() private _newMax?: number;
|
||||||
|
|
||||||
|
public showDialog(params: AutomationModeDialog): void {
|
||||||
|
this._opened = true;
|
||||||
|
this._params = params;
|
||||||
|
this._newMode = params.config.mode || AUTOMATION_DEFAULT_MODE;
|
||||||
|
this._newMax = isMaxMode(this._newMode)
|
||||||
|
? params.config.max || AUTOMATION_DEFAULT_MAX
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
public closeDialog(): void {
|
||||||
|
this._params.onClose();
|
||||||
|
|
||||||
|
if (this._opened) {
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
|
}
|
||||||
|
this._opened = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
if (!this._opened) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<ha-dialog
|
||||||
|
open
|
||||||
|
scrimClickAction
|
||||||
|
@closed=${this.closeDialog}
|
||||||
|
.heading=${createCloseHeading(
|
||||||
|
this.hass,
|
||||||
|
this.hass.localize("ui.panel.config.automation.editor.change_mode")
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ha-select
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.modes.label"
|
||||||
|
)}
|
||||||
|
.value=${this._newMode}
|
||||||
|
@selected=${this._modeChanged}
|
||||||
|
@closed=${stopPropagation}
|
||||||
|
fixedMenuPosition
|
||||||
|
.helper=${html`
|
||||||
|
<a
|
||||||
|
style="color: var(--secondary-text-color)"
|
||||||
|
href=${documentationUrl(this.hass, "/docs/automation/modes/")}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.modes.learn_more"
|
||||||
|
)}</a
|
||||||
|
>
|
||||||
|
`}
|
||||||
|
>
|
||||||
|
${MODES.map(
|
||||||
|
(mode) => html`
|
||||||
|
<mwc-list-item .value=${mode}>
|
||||||
|
${this.hass.localize(
|
||||||
|
`ui.panel.config.automation.editor.modes.${mode}`
|
||||||
|
) || mode}
|
||||||
|
</mwc-list-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</ha-select>
|
||||||
|
${isMaxMode(this._newMode)
|
||||||
|
? html`
|
||||||
|
<br /><ha-textfield
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
`ui.panel.config.automation.editor.max.${this._newMode}`
|
||||||
|
)}
|
||||||
|
type="number"
|
||||||
|
name="max"
|
||||||
|
.value=${this._newMax?.toString() ?? ""}
|
||||||
|
@change=${this._valueChanged}
|
||||||
|
class="max"
|
||||||
|
>
|
||||||
|
</ha-textfield>
|
||||||
|
`
|
||||||
|
: html``}
|
||||||
|
|
||||||
|
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
||||||
|
${this.hass.localize("ui.dialogs.generic.cancel")}
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button @click=${this._save} slot="primaryAction">
|
||||||
|
${this.hass.localize("ui.panel.config.automation.editor.change_mode")}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-dialog>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _modeChanged(ev) {
|
||||||
|
const mode = ev.target.value;
|
||||||
|
this._newMode = mode;
|
||||||
|
if (!isMaxMode(mode)) {
|
||||||
|
this._newMax = undefined;
|
||||||
|
} else if (!this._newMax) {
|
||||||
|
this._newMax = AUTOMATION_DEFAULT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const target = ev.target as any;
|
||||||
|
if (target.name === "max") {
|
||||||
|
this._newMax = Number(target.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _save(): void {
|
||||||
|
this._params.updateAutomation({
|
||||||
|
...this._params.config,
|
||||||
|
mode: this._newMode,
|
||||||
|
max: this._newMax,
|
||||||
|
});
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
haStyle,
|
||||||
|
haStyleDialog,
|
||||||
|
css`
|
||||||
|
ha-select,
|
||||||
|
ha-textfield {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dialog-automation-mode": DialogAutomationMode;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import type { AutomationConfig } from "../../../../data/automation";
|
||||||
|
|
||||||
|
export const loadAutomationModeDialog = () =>
|
||||||
|
import("./dialog-automation-mode");
|
||||||
|
|
||||||
|
export interface AutomationModeDialog {
|
||||||
|
config: AutomationConfig;
|
||||||
|
updateAutomation: (config: AutomationConfig) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const showAutomationModeDialog = (
|
||||||
|
element: HTMLElement,
|
||||||
|
dialogParams: AutomationModeDialog
|
||||||
|
): void => {
|
||||||
|
fireEvent(element, "show-dialog", {
|
||||||
|
dialogTag: "ha-dialog-automation-mode",
|
||||||
|
dialogImport: loadAutomationModeDialog,
|
||||||
|
dialogParams,
|
||||||
|
});
|
||||||
|
};
|
@ -0,0 +1,157 @@
|
|||||||
|
import "@material/mwc-button";
|
||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement, property, state } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
|
import { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||||
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
|
import type { HomeAssistant } from "../../../../types";
|
||||||
|
import type { AutomationRenameDialog } from "./show-dialog-automation-rename";
|
||||||
|
import "../../../../components/ha-textarea";
|
||||||
|
import "../../../../components/ha-alert";
|
||||||
|
import "../../../../components/ha-textfield";
|
||||||
|
|
||||||
|
@customElement("ha-dialog-automation-rename")
|
||||||
|
class DialogAutomationRename extends LitElement implements HassDialog {
|
||||||
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@state() private _opened = false;
|
||||||
|
|
||||||
|
@state() private _error?: string;
|
||||||
|
|
||||||
|
private _params!: AutomationRenameDialog;
|
||||||
|
|
||||||
|
private _newName?: string;
|
||||||
|
|
||||||
|
private _newDescription?: string;
|
||||||
|
|
||||||
|
public showDialog(params: AutomationRenameDialog): void {
|
||||||
|
this._opened = true;
|
||||||
|
this._params = params;
|
||||||
|
this._newName =
|
||||||
|
params.config.alias ||
|
||||||
|
this.hass.localize("ui.panel.config.automation.editor.default_name");
|
||||||
|
this._newDescription = params.config.description || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public closeDialog(): void {
|
||||||
|
this._params.onClose();
|
||||||
|
|
||||||
|
if (this._opened) {
|
||||||
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
|
}
|
||||||
|
this._opened = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
if (!this._opened) {
|
||||||
|
return html``;
|
||||||
|
}
|
||||||
|
return html`
|
||||||
|
<ha-dialog
|
||||||
|
open
|
||||||
|
scrimClickAction
|
||||||
|
@closed=${this.closeDialog}
|
||||||
|
.heading=${createCloseHeading(
|
||||||
|
this.hass,
|
||||||
|
this.hass.localize(
|
||||||
|
this._params.config.alias
|
||||||
|
? "ui.panel.config.automation.editor.rename"
|
||||||
|
: "ui.panel.config.automation.editor.save"
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
${this._error
|
||||||
|
? html`<ha-alert alert-type="error"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.missing_name"
|
||||||
|
)}</ha-alert
|
||||||
|
>`
|
||||||
|
: ""}
|
||||||
|
<ha-textfield
|
||||||
|
dialogInitialFocus
|
||||||
|
.value=${this._newName}
|
||||||
|
.placeholder=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.default_name"
|
||||||
|
)}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.alias"
|
||||||
|
)}
|
||||||
|
required
|
||||||
|
type="string"
|
||||||
|
@change=${this._valueChanged}
|
||||||
|
></ha-textfield>
|
||||||
|
|
||||||
|
<ha-textarea
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.description.label"
|
||||||
|
)}
|
||||||
|
.placeholder=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.description.placeholder"
|
||||||
|
)}
|
||||||
|
name="description"
|
||||||
|
autogrow
|
||||||
|
.value=${this._newDescription}
|
||||||
|
@change=${this._valueChanged}
|
||||||
|
></ha-textarea>
|
||||||
|
|
||||||
|
<mwc-button @click=${this.closeDialog} slot="secondaryAction">
|
||||||
|
${this.hass.localize("ui.dialogs.generic.cancel")}
|
||||||
|
</mwc-button>
|
||||||
|
<mwc-button @click=${this._save} slot="primaryAction">
|
||||||
|
${this.hass.localize(
|
||||||
|
this._params.config.alias
|
||||||
|
? "ui.panel.config.automation.editor.rename"
|
||||||
|
: "ui.panel.config.automation.editor.save"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</ha-dialog>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _valueChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
const target = ev.target as any;
|
||||||
|
if (target.name === "description") {
|
||||||
|
this._newDescription = target.value;
|
||||||
|
} else {
|
||||||
|
this._newName = target.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private _save(): void {
|
||||||
|
if (!this._newName) {
|
||||||
|
this._error = "Name is required";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._params.updateAutomation({
|
||||||
|
...this._params.config,
|
||||||
|
alias: this._newName,
|
||||||
|
description: this._newDescription,
|
||||||
|
});
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return [
|
||||||
|
haStyle,
|
||||||
|
haStyleDialog,
|
||||||
|
css`
|
||||||
|
ha-textfield,
|
||||||
|
ha-textarea {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
ha-alert {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-dialog-automation-rename": DialogAutomationRename;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
|
import type { AutomationConfig } from "../../../../data/automation";
|
||||||
|
|
||||||
|
export const loadAutomationRenameDialog = () =>
|
||||||
|
import("./dialog-automation-rename");
|
||||||
|
|
||||||
|
export interface AutomationRenameDialog {
|
||||||
|
config: AutomationConfig;
|
||||||
|
updateAutomation: (config: AutomationConfig) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const showAutomationRenameDialog = (
|
||||||
|
element: HTMLElement,
|
||||||
|
dialogParams: AutomationRenameDialog
|
||||||
|
): void => {
|
||||||
|
fireEvent(element, "show-dialog", {
|
||||||
|
dialogTag: "ha-dialog-automation-rename",
|
||||||
|
dialogImport: loadAutomationRenameDialog,
|
||||||
|
dialogParams,
|
||||||
|
});
|
||||||
|
};
|
@ -10,6 +10,7 @@ import "../../../components/ha-markdown";
|
|||||||
import "../../../components/ha-selector/ha-selector";
|
import "../../../components/ha-selector/ha-selector";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
|
import "../../../components/ha-alert";
|
||||||
import { BlueprintAutomationConfig } from "../../../data/automation";
|
import { BlueprintAutomationConfig } from "../../../data/automation";
|
||||||
import {
|
import {
|
||||||
BlueprintOrError,
|
BlueprintOrError,
|
||||||
@ -49,26 +50,23 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
protected render() {
|
protected render() {
|
||||||
const blueprint = this._blueprint;
|
const blueprint = this._blueprint;
|
||||||
return html`
|
return html`
|
||||||
<p class="introduction">
|
${this.stateObj?.state === "off"
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.introduction")}
|
? html`
|
||||||
</p>
|
<ha-alert alert-type="info">
|
||||||
<ha-card outlined>
|
${this.hass.localize(
|
||||||
<div class="card-content">
|
"ui.panel.config.automation.editor.disabled"
|
||||||
<ha-textarea
|
)}
|
||||||
.label=${this.hass.localize(
|
<mwc-button slot="action" @click=${this._enable}>
|
||||||
"ui.panel.config.automation.editor.description.label"
|
${this.hass.localize(
|
||||||
)}
|
"ui.panel.config.automation.editor.enable"
|
||||||
.placeholder=${this.hass.localize(
|
)}
|
||||||
"ui.panel.config.automation.editor.description.placeholder"
|
</mwc-button>
|
||||||
)}
|
</ha-alert>
|
||||||
name="description"
|
`
|
||||||
autogrow
|
: ""}
|
||||||
.value=${this.config.description || ""}
|
${this.config.description
|
||||||
@change=${this._valueChanged}
|
? html`<p class="description">${this.config.description}</p>`
|
||||||
></ha-textarea>
|
: ""}
|
||||||
</div>
|
|
||||||
</ha-card>
|
|
||||||
|
|
||||||
<ha-card
|
<ha-card
|
||||||
outlined
|
outlined
|
||||||
class="blueprint"
|
class="blueprint"
|
||||||
@ -198,19 +196,12 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private async _enable(): Promise<void> {
|
||||||
ev.stopPropagation();
|
if (!this.hass || !this.stateObj) {
|
||||||
const target = ev.target as any;
|
|
||||||
const name = target.name;
|
|
||||||
if (!name) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newVal = target.value;
|
await this.hass.callService("automation", "turn_on", {
|
||||||
if ((this.config![name] || "") === newVal) {
|
entity_id: this.stateObj.entity_id,
|
||||||
return;
|
|
||||||
}
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value: { ...this.config!, [name]: newVal },
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +213,7 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
ha-card.blueprint {
|
ha-card.blueprint {
|
||||||
margin: 24px auto;
|
margin: 0 auto;
|
||||||
}
|
}
|
||||||
.padding {
|
.padding {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
@ -233,7 +224,6 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
.blueprint-picker-container {
|
.blueprint-picker-container {
|
||||||
padding: 0 16px 16px;
|
padding: 0 16px 16px;
|
||||||
}
|
}
|
||||||
ha-textarea,
|
|
||||||
ha-textfield,
|
ha-textfield,
|
||||||
ha-blueprint-picker {
|
ha-blueprint-picker {
|
||||||
display: block;
|
display: block;
|
||||||
@ -251,12 +241,19 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
p {
|
p {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.description {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
ha-settings-row {
|
ha-settings-row {
|
||||||
--paper-time-input-justify-content: flex-end;
|
--paper-time-input-justify-content: flex-end;
|
||||||
--settings-row-content-width: 100%;
|
--settings-row-content-width: 100%;
|
||||||
--settings-row-prefix-display: contents;
|
--settings-row-prefix-display: contents;
|
||||||
border-top: 1px solid var(--divider-color);
|
border-top: 1px solid var(--divider-color);
|
||||||
}
|
}
|
||||||
|
ha-alert {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ export default class HaAutomationConditionEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public yamlMode = false;
|
@property({ type: Boolean }) public yamlMode = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _processedCondition = memoizeOne((condition) =>
|
private _processedCondition = memoizeOne((condition) =>
|
||||||
expandConditionWithShorthand(condition)
|
expandConditionWithShorthand(condition)
|
||||||
);
|
);
|
||||||
@ -60,7 +62,11 @@ export default class HaAutomationConditionEditor extends LitElement {
|
|||||||
<div>
|
<div>
|
||||||
${dynamicElement(
|
${dynamicElement(
|
||||||
`ha-automation-condition-${condition.condition}`,
|
`ha-automation-condition-${condition.condition}`,
|
||||||
{ hass: this.hass, condition: condition }
|
{
|
||||||
|
hass: this.hass,
|
||||||
|
condition: condition,
|
||||||
|
reOrderMode: this.reOrderMode,
|
||||||
|
}
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`}
|
`}
|
||||||
|
@ -70,6 +70,10 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
|
|
||||||
@property() public condition!: Condition;
|
@property() public condition!: Condition;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public hideMenu = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
@state() private _yamlMode = false;
|
@state() private _yamlMode = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
@ -103,96 +107,106 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
)}
|
)}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<ha-button-menu
|
<slot name="icons" slot="icons"></slot>
|
||||||
slot="icons"
|
${this.hideMenu
|
||||||
fixed
|
? ""
|
||||||
corner="BOTTOM_START"
|
: html`
|
||||||
@action=${this._handleAction}
|
<ha-button-menu
|
||||||
@click=${preventDefault}
|
slot="icons"
|
||||||
>
|
fixed
|
||||||
<ha-icon-button
|
corner="BOTTOM_START"
|
||||||
slot="trigger"
|
@action=${this._handleAction}
|
||||||
.label=${this.hass.localize("ui.common.menu")}
|
@click=${preventDefault}
|
||||||
.path=${mdiDotsVertical}
|
>
|
||||||
>
|
<ha-icon-button
|
||||||
</ha-icon-button>
|
slot="trigger"
|
||||||
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
|
.path=${mdiDotsVertical}
|
||||||
|
>
|
||||||
|
</ha-icon-button>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.test"
|
"ui.panel.config.automation.editor.conditions.test"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiFlask}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiFlask}></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.conditions.rename"
|
"ui.panel.config.automation.editor.conditions.rename"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
<mwc-list-item graphic="icon">
|
.path=${mdiRenameBox}
|
||||||
${this.hass.localize(
|
></ha-svg-icon>
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
</mwc-list-item>
|
||||||
)}
|
<mwc-list-item graphic="icon">
|
||||||
<ha-svg-icon
|
${this.hass.localize(
|
||||||
slot="graphic"
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
.path=${mdiContentDuplicate}
|
)}
|
||||||
></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
${this.hass.localize(
|
||||||
${!this._yamlMode
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
? html`<ha-svg-icon
|
)}
|
||||||
class="selected_menu_item"
|
${!this._yamlMode
|
||||||
slot="graphic"
|
? html`<ha-svg-icon
|
||||||
.path=${mdiCheck}
|
class="selected_menu_item"
|
||||||
></ha-svg-icon>`
|
slot="graphic"
|
||||||
: ``}
|
.path=${mdiCheck}
|
||||||
</mwc-list-item>
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
)}
|
)}
|
||||||
${this._yamlMode
|
${this._yamlMode
|
||||||
? html`<ha-svg-icon
|
? html`<ha-svg-icon
|
||||||
class="selected_menu_item"
|
class="selected_menu_item"
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${mdiCheck}
|
.path=${mdiCheck}
|
||||||
></ha-svg-icon>`
|
></ha-svg-icon>`
|
||||||
: ``}
|
: ``}
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<li divider role="separator"></li>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.condition.enabled === false
|
${this.condition.enabled === false
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.enable"
|
"ui.panel.config.automation.editor.actions.enable"
|
||||||
)
|
)
|
||||||
: this.hass.localize(
|
: this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.disable"
|
"ui.panel.config.automation.editor.actions.disable"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${this.condition.enabled === false
|
.path=${this.condition.enabled === false
|
||||||
? mdiPlayCircleOutline
|
? mdiPlayCircleOutline
|
||||||
: mdiStopCircleOutline}
|
: mdiStopCircleOutline}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
<mwc-list-item class="warning" graphic="icon">
|
<mwc-list-item class="warning" graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.actions.delete"
|
"ui.panel.config.automation.editor.actions.delete"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
class="warning"
|
class="warning"
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${mdiDelete}
|
.path=${mdiDelete}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
|
`}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
@ -226,6 +240,7 @@ export default class HaAutomationConditionRow extends LitElement {
|
|||||||
.yamlMode=${this._yamlMode}
|
.yamlMode=${this._yamlMode}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.condition=${this.condition}
|
.condition=${this.condition}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition-editor>
|
></ha-automation-condition-editor>
|
||||||
</div>
|
</div>
|
||||||
</ha-expansion-panel>
|
</ha-expansion-panel>
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import { mdiPlus } from "@mdi/js";
|
|
||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
|
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
||||||
|
import deepClone from "deep-clone-simple";
|
||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
|
import { repeat } from "lit/directives/repeat";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import type { ActionDetail } from "@material/mwc-list";
|
import type { SortableEvent } from "sortablejs";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-svg-icon";
|
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import type { Condition } from "../../../../data/automation";
|
import type { Condition } from "../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-condition-row";
|
import "./ha-automation-condition-row";
|
||||||
@ -16,6 +17,14 @@ import type HaAutomationConditionRow from "./ha-automation-condition-row";
|
|||||||
// Uncommenting these and this element doesn't load
|
// Uncommenting these and this element doesn't load
|
||||||
// import "./types/ha-automation-condition-not";
|
// import "./types/ha-automation-condition-not";
|
||||||
// import "./types/ha-automation-condition-or";
|
// import "./types/ha-automation-condition-or";
|
||||||
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
import { CONDITION_TYPES } from "../../../../data/condition";
|
||||||
|
import {
|
||||||
|
loadSortable,
|
||||||
|
SortableInstance,
|
||||||
|
} from "../../../../resources/sortable.ondemand";
|
||||||
import "./types/ha-automation-condition-and";
|
import "./types/ha-automation-condition-and";
|
||||||
import "./types/ha-automation-condition-device";
|
import "./types/ha-automation-condition-device";
|
||||||
import "./types/ha-automation-condition-numeric_state";
|
import "./types/ha-automation-condition-numeric_state";
|
||||||
@ -25,10 +34,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 { CONDITION_TYPES } from "../../../../data/condition";
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
|
||||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
|
||||||
|
|
||||||
@customElement("ha-automation-condition")
|
@customElement("ha-automation-condition")
|
||||||
export default class HaAutomationCondition extends LitElement {
|
export default class HaAutomationCondition extends LitElement {
|
||||||
@ -36,11 +42,23 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
|
|
||||||
@property() public conditions!: Condition[];
|
@property() public conditions!: Condition[];
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _focusLastConditionOnChange = false;
|
private _focusLastConditionOnChange = false;
|
||||||
|
|
||||||
private _conditionKeys = new WeakMap<Condition, string>();
|
private _conditionKeys = new WeakMap<Condition, string>();
|
||||||
|
|
||||||
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues) {
|
protected updated(changedProperties: PropertyValues) {
|
||||||
|
if (changedProperties.has("reOrderMode")) {
|
||||||
|
if (this.reOrderMode) {
|
||||||
|
this._createSortable();
|
||||||
|
} else {
|
||||||
|
this._destroySortable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!changedProperties.has("conditions")) {
|
if (!changedProperties.has("conditions")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -82,19 +100,53 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
return html`
|
return html`
|
||||||
${repeat(
|
<div class="conditions">
|
||||||
this.conditions,
|
${repeat(
|
||||||
(condition) => this._getKey(condition),
|
this.conditions,
|
||||||
(cond, idx) => html`
|
(condition) => this._getKey(condition),
|
||||||
<ha-automation-condition-row
|
(cond, idx) => html`
|
||||||
.index=${idx}
|
<ha-automation-condition-row
|
||||||
.condition=${cond}
|
.index=${idx}
|
||||||
@duplicate=${this._duplicateCondition}
|
.totalConditions=${this.conditions.length}
|
||||||
@value-changed=${this._conditionChanged}
|
.condition=${cond}
|
||||||
.hass=${this.hass}
|
.hideMenu=${this.reOrderMode}
|
||||||
></ha-automation-condition-row>
|
.reOrderMode=${this.reOrderMode}
|
||||||
`
|
@duplicate=${this._duplicateCondition}
|
||||||
)}
|
@move-condition=${this._move}
|
||||||
|
@value-changed=${this._conditionChanged}
|
||||||
|
.hass=${this.hass}
|
||||||
|
>
|
||||||
|
${this.reOrderMode
|
||||||
|
? html`
|
||||||
|
<ha-icon-button
|
||||||
|
.index=${idx}
|
||||||
|
slot="icons"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.move_up"
|
||||||
|
)}
|
||||||
|
.path=${mdiArrowUp}
|
||||||
|
@click=${this._moveUp}
|
||||||
|
.disabled=${idx === 0}
|
||||||
|
></ha-icon-button>
|
||||||
|
<ha-icon-button
|
||||||
|
.index=${idx}
|
||||||
|
slot="icons"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.move_down"
|
||||||
|
)}
|
||||||
|
.path=${mdiArrowDown}
|
||||||
|
@click=${this._moveDown}
|
||||||
|
.disabled=${idx === this.conditions.length - 1}
|
||||||
|
></ha-icon-button>
|
||||||
|
<div class="handle" slot="icons">
|
||||||
|
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</ha-automation-condition-row>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
<ha-button-menu fixed @action=${this._addCondition}>
|
<ha-button-menu fixed @action=${this._addCondition}>
|
||||||
<mwc-button
|
<mwc-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@ -116,6 +168,36 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _createSortable() {
|
||||||
|
const Sortable = await loadSortable();
|
||||||
|
this._sortable = new Sortable(
|
||||||
|
this.shadowRoot!.querySelector(".conditions")!,
|
||||||
|
{
|
||||||
|
animation: 150,
|
||||||
|
fallbackClass: "sortable-fallback",
|
||||||
|
handle: ".handle",
|
||||||
|
onChoose: (evt: SortableEvent) => {
|
||||||
|
(evt.item as any).placeholder =
|
||||||
|
document.createComment("sort-placeholder");
|
||||||
|
evt.item.after((evt.item as any).placeholder);
|
||||||
|
},
|
||||||
|
onEnd: (evt: SortableEvent) => {
|
||||||
|
// put back in original location
|
||||||
|
if ((evt.item as any).placeholder) {
|
||||||
|
(evt.item as any).placeholder.replaceWith(evt.item);
|
||||||
|
delete (evt.item as any).placeholder;
|
||||||
|
}
|
||||||
|
this._dragged(evt);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _destroySortable() {
|
||||||
|
this._sortable?.destroy();
|
||||||
|
this._sortable = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private _getKey(condition: Condition) {
|
private _getKey(condition: Condition) {
|
||||||
if (!this._conditionKeys.has(condition)) {
|
if (!this._conditionKeys.has(condition)) {
|
||||||
this._conditionKeys.set(condition, Math.random().toString());
|
this._conditionKeys.set(condition, Math.random().toString());
|
||||||
@ -142,6 +224,30 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: conditions });
|
fireEvent(this, "value-changed", { value: conditions });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _moveUp(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = index - 1;
|
||||||
|
this._move(index, newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _moveDown(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = index + 1;
|
||||||
|
this._move(index, newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _dragged(ev: SortableEvent): void {
|
||||||
|
if (ev.oldIndex === ev.newIndex) return;
|
||||||
|
this._move(ev.oldIndex!, ev.newIndex!);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _move(index: number, newIndex: number) {
|
||||||
|
const conditions = this.conditions.concat();
|
||||||
|
const condition = conditions.splice(index, 1)[0];
|
||||||
|
conditions.splice(newIndex, 0, condition);
|
||||||
|
fireEvent(this, "value-changed", { value: conditions });
|
||||||
|
}
|
||||||
|
|
||||||
private _conditionChanged(ev: CustomEvent) {
|
private _conditionChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const conditions = [...this.conditions];
|
const conditions = [...this.conditions];
|
||||||
@ -186,16 +292,27 @@ export default class HaAutomationCondition extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return [
|
||||||
ha-automation-condition-row {
|
sortableStyles,
|
||||||
display: block;
|
css`
|
||||||
margin-bottom: 16px;
|
ha-automation-condition-row {
|
||||||
scroll-margin-top: 48px;
|
display: block;
|
||||||
}
|
margin-bottom: 16px;
|
||||||
ha-svg-icon {
|
scroll-margin-top: 48px;
|
||||||
height: 20px;
|
}
|
||||||
}
|
ha-svg-icon {
|
||||||
`;
|
height: 20px;
|
||||||
|
}
|
||||||
|
.handle {
|
||||||
|
cursor: move;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
.handle ha-svg-icon {
|
||||||
|
pointer-events: none;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public condition!: LogicalCondition;
|
@property({ attribute: false }) public condition!: LogicalCondition;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
public static get defaultConfig() {
|
public static get defaultConfig() {
|
||||||
return {
|
return {
|
||||||
conditions: [],
|
conditions: [],
|
||||||
@ -24,6 +26,7 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
|
|||||||
.conditions=${this.condition.conditions || []}
|
.conditions=${this.condition.conditions || []}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
|
import "@material/mwc-button";
|
||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import {
|
import {
|
||||||
mdiCheck,
|
mdiCheck,
|
||||||
mdiContentDuplicate,
|
mdiContentDuplicate,
|
||||||
mdiContentSave,
|
mdiContentSave,
|
||||||
|
mdiDebugStepOver,
|
||||||
mdiDelete,
|
mdiDelete,
|
||||||
mdiDotsVertical,
|
mdiDotsVertical,
|
||||||
mdiInformationOutline,
|
mdiInformationOutline,
|
||||||
mdiPencil,
|
|
||||||
mdiPlay,
|
mdiPlay,
|
||||||
mdiPlayCircleOutline,
|
mdiPlayCircleOutline,
|
||||||
mdiRenameBox,
|
mdiRenameBox,
|
||||||
|
mdiSort,
|
||||||
mdiStopCircleOutline,
|
mdiStopCircleOutline,
|
||||||
mdiTransitConnection,
|
mdiTransitConnection,
|
||||||
} from "@mdi/js";
|
} from "@mdi/js";
|
||||||
@ -24,7 +26,7 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { property, state, query } 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 { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
@ -48,7 +50,6 @@ import {
|
|||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
showPromptDialog,
|
|
||||||
} from "../../../dialogs/generic/show-dialog-box";
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
import "../../../layouts/ha-app-layout";
|
import "../../../layouts/ha-app-layout";
|
||||||
import "../../../layouts/hass-subpage";
|
import "../../../layouts/hass-subpage";
|
||||||
@ -57,9 +58,11 @@ import { haStyle } from "../../../resources/styles";
|
|||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import { showToast } from "../../../util/toast";
|
import { showToast } from "../../../util/toast";
|
||||||
import "../ha-config-section";
|
import "../ha-config-section";
|
||||||
import { configSections } from "../ha-panel-config";
|
import { showAutomationModeDialog } from "./automation-mode-dialog/show-dialog-automation-mode";
|
||||||
|
import { showAutomationRenameDialog } from "./automation-rename-dialog/show-dialog-automation-rename";
|
||||||
import "./blueprint-automation-editor";
|
import "./blueprint-automation-editor";
|
||||||
import "./manual-automation-editor";
|
import "./manual-automation-editor";
|
||||||
|
import type { HaManualAutomationEditor } from "./manual-automation-editor";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HTMLElementTagNameMap {
|
interface HTMLElementTagNameMap {
|
||||||
@ -99,7 +102,10 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _mode: "gui" | "yaml" = "gui";
|
@state() private _mode: "gui" | "yaml" = "gui";
|
||||||
|
|
||||||
@query("ha-yaml-editor", true) private _editor?: HaYamlEditor;
|
@query("ha-yaml-editor", true) private _yamlEditor?: HaYamlEditor;
|
||||||
|
|
||||||
|
@query("manual-automation-editor")
|
||||||
|
private _manualEditor?: HaManualAutomationEditor;
|
||||||
|
|
||||||
private _configSubscriptions: Record<
|
private _configSubscriptions: Record<
|
||||||
string,
|
string,
|
||||||
@ -118,8 +124,28 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.backCallback=${this._backTapped}
|
.backCallback=${this._backTapped}
|
||||||
.tabs=${configSections.automations}
|
.header=${!this._config
|
||||||
|
? ""
|
||||||
|
: this._config.alias ||
|
||||||
|
this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.default_name"
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
|
${this._config?.id && !this.narrow
|
||||||
|
? html`
|
||||||
|
<a
|
||||||
|
class="trace-link"
|
||||||
|
href="/config/automation/trace/${this._config.id}"
|
||||||
|
slot="toolbar-icon"
|
||||||
|
>
|
||||||
|
<mwc-button>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.show_trace"
|
||||||
|
)}
|
||||||
|
</mwc-button>
|
||||||
|
</a>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
<ha-button-menu corner="BOTTOM_START" slot="toolbar-icon">
|
<ha-button-menu corner="BOTTOM_START" slot="toolbar-icon">
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="trigger"
|
slot="trigger"
|
||||||
@ -144,7 +170,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiPlay}></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
|
|
||||||
${stateObj && this._config
|
${stateObj && this._config && this.narrow
|
||||||
? html`<a href="/config/automation/trace/${this._config.id}">
|
? html`<a href="/config/automation/trace/${this._config.id}">
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
@ -158,11 +184,42 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
</a>`
|
</a>`
|
||||||
: ""}
|
: ""}
|
||||||
|
|
||||||
<mwc-list-item graphic="icon" @click=${this._promptAutomationAlias}>
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@click=${this._promptAutomationAlias}
|
||||||
|
.disabled=${!this.automationId || this._mode === "yaml"}
|
||||||
|
>
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.rename")}
|
${this.hass.localize("ui.panel.config.automation.editor.rename")}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
|
|
||||||
|
${this._config && !("use_blueprint" in this._config)
|
||||||
|
? html`
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@click=${this._promptAutomationMode}
|
||||||
|
.disabled=${!this.automationId || this._mode === "yaml"}
|
||||||
|
>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.change_mode"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiDebugStepOver}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
|
||||||
|
<mwc-list-item
|
||||||
|
graphic="icon"
|
||||||
|
@click=${this._toggleReOrderMode}
|
||||||
|
.disabled=${this._mode !== "gui"}
|
||||||
|
>
|
||||||
|
${this.hass.localize("ui.panel.config.automation.editor.re_order")}
|
||||||
|
<ha-svg-icon slot="graphic" .path=${mdiSort}></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
.disabled=${!this.automationId}
|
.disabled=${!this.automationId}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@ -205,12 +262,12 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
.disabled=${!stateObj}
|
.disabled=${!stateObj}
|
||||||
@click=${this._toggle}
|
@click=${this._toggle}
|
||||||
>
|
>
|
||||||
${!stateObj || stateObj.state === "off"
|
${stateObj?.state === "off"
|
||||||
? this.hass.localize("ui.panel.config.automation.editor.enable")
|
? this.hass.localize("ui.panel.config.automation.editor.enable")
|
||||||
: this.hass.localize("ui.panel.config.automation.editor.disable")}
|
: this.hass.localize("ui.panel.config.automation.editor.disable")}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${!stateObj || stateObj.state === "off"
|
.path=${stateObj?.state === "off"
|
||||||
? mdiPlayCircleOutline
|
? mdiPlayCircleOutline
|
||||||
: mdiStopCircleOutline}
|
: mdiStopCircleOutline}
|
||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
@ -234,14 +291,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
|
|
||||||
${this._config
|
${this._config
|
||||||
? html`
|
? html`
|
||||||
${this.narrow
|
|
||||||
? html`<span slot="header"
|
|
||||||
>${this._config!.alias ||
|
|
||||||
this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.default_name"
|
|
||||||
)}</span
|
|
||||||
>`
|
|
||||||
: ""}
|
|
||||||
<div
|
<div
|
||||||
class="content ${classMap({
|
class="content ${classMap({
|
||||||
"yaml-mode": this._mode === "yaml",
|
"yaml-mode": this._mode === "yaml",
|
||||||
@ -249,65 +298,48 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
@subscribe-automation-config=${this._subscribeAutomationConfig}
|
@subscribe-automation-config=${this._subscribeAutomationConfig}
|
||||||
>
|
>
|
||||||
${this._errors
|
${this._errors
|
||||||
? html`<div class="errors">${this._errors}</div>`
|
? html`<ha-alert alert-type="error">
|
||||||
|
${this._errors}
|
||||||
|
</ha-alert>`
|
||||||
: ""}
|
: ""}
|
||||||
${this._mode === "gui"
|
${this._mode === "gui"
|
||||||
? html`
|
? "use_blueprint" in this._config
|
||||||
${this.narrow
|
? html`
|
||||||
? ""
|
<blueprint-automation-editor
|
||||||
: html`
|
.hass=${this.hass}
|
||||||
<div class="header-name">
|
.narrow=${this.narrow}
|
||||||
<h1>
|
.isWide=${this.isWide}
|
||||||
${this._config!.alias ||
|
.stateObj=${stateObj}
|
||||||
this.hass.localize(
|
.config=${this._config}
|
||||||
"ui.panel.config.automation.editor.default_name"
|
@value-changed=${this._valueChanged}
|
||||||
)}
|
></blueprint-automation-editor>
|
||||||
</h1>
|
`
|
||||||
<ha-icon-button
|
: html`
|
||||||
.path=${mdiPencil}
|
<manual-automation-editor
|
||||||
@click=${this._promptAutomationAlias}
|
.hass=${this.hass}
|
||||||
.label=${this.hass.localize(
|
.narrow=${this.narrow}
|
||||||
"ui.panel.config.automation.editor.rename"
|
.isWide=${this.isWide}
|
||||||
)}
|
.stateObj=${stateObj}
|
||||||
></ha-icon-button>
|
.config=${this._config}
|
||||||
</div>
|
@value-changed=${this._valueChanged}
|
||||||
`}
|
></manual-automation-editor>
|
||||||
${"use_blueprint" in this._config
|
`
|
||||||
? html`
|
|
||||||
<blueprint-automation-editor
|
|
||||||
.hass=${this.hass}
|
|
||||||
.narrow=${this.narrow}
|
|
||||||
.isWide=${this.isWide}
|
|
||||||
.stateObj=${stateObj}
|
|
||||||
.config=${this._config}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
></blueprint-automation-editor>
|
|
||||||
`
|
|
||||||
: html`
|
|
||||||
<manual-automation-editor
|
|
||||||
.hass=${this.hass}
|
|
||||||
.narrow=${this.narrow}
|
|
||||||
.isWide=${this.isWide}
|
|
||||||
.stateObj=${stateObj}
|
|
||||||
.config=${this._config}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
></manual-automation-editor>
|
|
||||||
`}
|
|
||||||
`
|
|
||||||
: this._mode === "yaml"
|
: this._mode === "yaml"
|
||||||
? html`
|
? html`
|
||||||
${!this.narrow
|
${stateObj?.state === "off"
|
||||||
? html`
|
? html`
|
||||||
<ha-card outlined>
|
<ha-alert alert-type="info">
|
||||||
<div class="card-header">
|
${this.hass.localize(
|
||||||
${this._config.alias ||
|
"ui.panel.config.automation.editor.disabled"
|
||||||
this.hass.localize(
|
)}
|
||||||
"ui.panel.config.automation.editor.default_name"
|
<mwc-button slot="action" @click=${this._toggle}>
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.enable"
|
||||||
)}
|
)}
|
||||||
</div>
|
</mwc-button>
|
||||||
</ha-card>
|
</ha-alert>
|
||||||
`
|
`
|
||||||
: ``}
|
: ""}
|
||||||
<ha-yaml-editor
|
<ha-yaml-editor
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.defaultValue=${this._preprocessYaml()}
|
.defaultValue=${this._preprocessYaml()}
|
||||||
@ -477,8 +509,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _copyYaml(): Promise<void> {
|
private async _copyYaml(): Promise<void> {
|
||||||
if (this._editor?.yaml) {
|
if (this._yamlEditor?.yaml) {
|
||||||
await copyToClipboard(this._editor.yaml);
|
await copyToClipboard(this._yamlEditor.yaml);
|
||||||
showToast(this, {
|
showToast(this, {
|
||||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||||
});
|
});
|
||||||
@ -559,40 +591,46 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
this._mode = "yaml";
|
this._mode = "yaml";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _promptAutomationAlias(): Promise<string | null> {
|
private _toggleReOrderMode() {
|
||||||
const result = await showPromptDialog(this, {
|
if (this._manualEditor) {
|
||||||
title: this.hass.localize(
|
this._manualEditor.reOrderMode = !this._manualEditor.reOrderMode;
|
||||||
"ui.panel.config.automation.editor.automation_alias"
|
|
||||||
),
|
|
||||||
inputLabel: this.hass.localize("ui.panel.config.automation.editor.alias"),
|
|
||||||
inputType: "string",
|
|
||||||
placeholder: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.default_name"
|
|
||||||
),
|
|
||||||
defaultValue: this._config!.alias,
|
|
||||||
confirmText: this.hass.localize("ui.common.submit"),
|
|
||||||
});
|
|
||||||
if (result) {
|
|
||||||
this._config!.alias = result;
|
|
||||||
this._dirty = true;
|
|
||||||
this.requestUpdate();
|
|
||||||
}
|
}
|
||||||
return result;
|
}
|
||||||
|
|
||||||
|
private async _promptAutomationAlias(): Promise<void> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
showAutomationRenameDialog(this, {
|
||||||
|
config: this._config!,
|
||||||
|
updateAutomation: (config) => {
|
||||||
|
this._config = config;
|
||||||
|
this._dirty = true;
|
||||||
|
this.requestUpdate();
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
onClose: () => resolve(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _promptAutomationMode(): Promise<void> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
showAutomationModeDialog(this, {
|
||||||
|
config: this._config!,
|
||||||
|
updateAutomation: (config) => {
|
||||||
|
this._config = config;
|
||||||
|
this._dirty = true;
|
||||||
|
this.requestUpdate();
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
onClose: () => resolve(),
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _saveAutomation(): Promise<void> {
|
private async _saveAutomation(): Promise<void> {
|
||||||
const id = this.automationId || String(Date.now());
|
const id = this.automationId || String(Date.now());
|
||||||
if (!this._config!.alias) {
|
if (!this.automationId) {
|
||||||
const alias = await this._promptAutomationAlias();
|
await this._promptAutomationAlias();
|
||||||
if (!alias) {
|
|
||||||
showAlertDialog(this, {
|
|
||||||
text: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.missing_name"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this._config!.alias = alias;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hass!.callApi(
|
this.hass!.callApi(
|
||||||
@ -637,11 +675,6 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
ha-card {
|
ha-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.errors {
|
|
||||||
padding: 20px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: var(--error-color);
|
|
||||||
}
|
|
||||||
.content {
|
.content {
|
||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
}
|
}
|
||||||
@ -651,6 +684,9 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
|
.trace-link {
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
manual-automation-editor,
|
manual-automation-editor,
|
||||||
blueprint-automation-editor {
|
blueprint-automation-editor {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
import { mdiHelpCircle, mdiRobot } from "@mdi/js";
|
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 { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import "../../../components/entity/ha-entity-toggle";
|
import "../../../components/entity/ha-entity-toggle";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
|
import "../../../components/ha-icon-button";
|
||||||
|
import "../../../components/ha-alert";
|
||||||
import "../../../components/ha-textarea";
|
import "../../../components/ha-textarea";
|
||||||
import "../../../components/ha-textfield";
|
import "../../../components/ha-textfield";
|
||||||
import "../../../components/ha-icon-button";
|
|
||||||
import {
|
import {
|
||||||
AUTOMATION_DEFAULT_MODE,
|
|
||||||
Condition,
|
Condition,
|
||||||
ManualAutomationConfig,
|
ManualAutomationConfig,
|
||||||
Trigger,
|
Trigger,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import { Action, isMaxMode, MODES } from "../../../data/script";
|
import { 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";
|
||||||
@ -35,85 +35,47 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public stateObj?: HassEntity;
|
@property({ attribute: false }) public stateObj?: HassEntity;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true, attribute: "re-order-mode" })
|
||||||
|
public reOrderMode = false;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
<ha-card outlined>
|
${this.stateObj?.state === "off"
|
||||||
${this.stateObj && this.stateObj.state === "off"
|
? html`
|
||||||
? html`<div class="disabled-bar">
|
<ha-alert alert-type="info">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.disabled"
|
"ui.panel.config.automation.editor.disabled"
|
||||||
)}
|
)}
|
||||||
</div>`
|
<mwc-button slot="action" @click=${this._enable}>
|
||||||
: ""}
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.enable"
|
||||||
<ha-expansion-panel leftChevron>
|
)}
|
||||||
<h3 slot="header">
|
</mwc-button>
|
||||||
<ha-svg-icon class="settings-icon" .path=${mdiRobot}></ha-svg-icon>
|
</ha-alert>
|
||||||
${this.hass.localize(
|
`
|
||||||
"ui.panel.config.automation.editor.automation_settings"
|
: ""}
|
||||||
)}
|
${this.reOrderMode
|
||||||
</h3>
|
? html`
|
||||||
<div class="card-content">
|
<ha-alert
|
||||||
<ha-textarea
|
alert-type="info"
|
||||||
.label=${this.hass.localize(
|
.title=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.description.label"
|
"ui.panel.config.automation.editor.re_order_mode.title"
|
||||||
)}
|
)}
|
||||||
.placeholder=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.description.placeholder"
|
|
||||||
)}
|
|
||||||
name="description"
|
|
||||||
autogrow
|
|
||||||
.value=${this.config.description || ""}
|
|
||||||
@change=${this._valueChanged}
|
|
||||||
></ha-textarea>
|
|
||||||
<ha-select
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.modes.label"
|
|
||||||
)}
|
|
||||||
.value=${this.config.mode || AUTOMATION_DEFAULT_MODE}
|
|
||||||
@selected=${this._modeChanged}
|
|
||||||
fixedMenuPosition
|
|
||||||
.helper=${html`
|
|
||||||
<a
|
|
||||||
style="color: var(--secondary-text-color)"
|
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/modes/")}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
>${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.modes.learn_more"
|
|
||||||
)}</a
|
|
||||||
>
|
|
||||||
`}
|
|
||||||
>
|
>
|
||||||
${MODES.map(
|
${this.hass.localize(
|
||||||
(mode) => html`
|
"ui.panel.config.automation.editor.re_order_mode.description"
|
||||||
<mwc-list-item .value=${mode}>
|
|
||||||
${this.hass.localize(
|
|
||||||
`ui.panel.config.automation.editor.modes.${mode}`
|
|
||||||
) || mode}
|
|
||||||
</mwc-list-item>
|
|
||||||
`
|
|
||||||
)}
|
)}
|
||||||
</ha-select>
|
<mwc-button slot="action" @click=${this._exitReOrderMode}>
|
||||||
${this.config.mode && isMaxMode(this.config.mode)
|
${this.hass.localize(
|
||||||
? html`
|
"ui.panel.config.automation.editor.re_order_mode.exit"
|
||||||
<br /><ha-textfield
|
)}
|
||||||
.label=${this.hass.localize(
|
</mwc-button>
|
||||||
`ui.panel.config.automation.editor.max.${this.config.mode}`
|
</ha-alert>
|
||||||
)}
|
`
|
||||||
type="number"
|
: ""}
|
||||||
name="max"
|
${this.config.description
|
||||||
.value=${this.config.max || "10"}
|
? html`<p class="description">${this.config.description}</p>`
|
||||||
@change=${this._valueChanged}
|
: ""}
|
||||||
class="max"
|
|
||||||
>
|
|
||||||
</ha-textfield>
|
|
||||||
`
|
|
||||||
: html``}
|
|
||||||
</div>
|
|
||||||
</ha-expansion-panel>
|
|
||||||
</ha-card>
|
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h2 id="triggers-heading" class="name">
|
<h2 id="triggers-heading" class="name">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
@ -140,6 +102,7 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
.triggers=${this.config.trigger}
|
.triggers=${this.config.trigger}
|
||||||
@value-changed=${this._triggerChanged}
|
@value-changed=${this._triggerChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-trigger>
|
></ha-automation-trigger>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
@ -168,6 +131,7 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
.conditions=${this.config.condition || []}
|
.conditions=${this.config.condition || []}
|
||||||
@value-changed=${this._conditionChanged}
|
@value-changed=${this._conditionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-condition>
|
></ha-automation-condition>
|
||||||
|
|
||||||
<div class="header">
|
<div class="header">
|
||||||
@ -176,18 +140,20 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
"ui.panel.config.automation.editor.actions.header"
|
"ui.panel.config.automation.editor.actions.header"
|
||||||
)}
|
)}
|
||||||
</h2>
|
</h2>
|
||||||
<a
|
<div>
|
||||||
href=${documentationUrl(this.hass, "/docs/automation/action/")}
|
<a
|
||||||
target="_blank"
|
href=${documentationUrl(this.hass, "/docs/automation/action/")}
|
||||||
rel="noreferrer"
|
target="_blank"
|
||||||
>
|
rel="noreferrer"
|
||||||
<ha-icon-button
|
>
|
||||||
.path=${mdiHelpCircle}
|
<ha-icon-button
|
||||||
.label=${this.hass.localize(
|
.path=${mdiHelpCircle}
|
||||||
"ui.panel.config.automation.editor.actions.learn_more"
|
.label=${this.hass.localize(
|
||||||
)}
|
"ui.panel.config.automation.editor.actions.learn_more"
|
||||||
></ha-icon-button>
|
)}
|
||||||
</a>
|
></ha-icon-button>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ha-automation-action
|
<ha-automation-action
|
||||||
@ -197,50 +163,13 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
@value-changed=${this._actionChanged}
|
@value-changed=${this._actionChanged}
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
|
.reOrderMode=${this.reOrderMode}
|
||||||
></ha-automation-action>
|
></ha-automation-action>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private _exitReOrderMode() {
|
||||||
ev.stopPropagation();
|
this.reOrderMode = !this.reOrderMode;
|
||||||
const target = ev.target as any;
|
|
||||||
const name = target.name;
|
|
||||||
if (!name) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let newVal = target.value;
|
|
||||||
if (target.type === "number") {
|
|
||||||
newVal = Number(newVal);
|
|
||||||
}
|
|
||||||
if ((this.config![name] || "") === newVal) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value: { ...this.config!, [name]: newVal },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private _modeChanged(ev) {
|
|
||||||
const mode = ev.target.value;
|
|
||||||
|
|
||||||
if (
|
|
||||||
mode === this.config!.mode ||
|
|
||||||
(!this.config!.mode && mode === MODES[0])
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const value = {
|
|
||||||
...this.config!,
|
|
||||||
mode,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!isMaxMode(mode)) {
|
|
||||||
delete value.max;
|
|
||||||
}
|
|
||||||
|
|
||||||
fireEvent(this, "value-changed", {
|
|
||||||
value,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _triggerChanged(ev: CustomEvent): void {
|
private _triggerChanged(ev: CustomEvent): void {
|
||||||
@ -267,6 +196,15 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _enable(): Promise<void> {
|
||||||
|
if (!this.hass || !this.stateObj) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.hass.callService("automation", "turn_on", {
|
||||||
|
entity_id: this.stateObj.entity_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
haStyle,
|
haStyle,
|
||||||
@ -280,11 +218,9 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
.link-button-row {
|
.link-button-row {
|
||||||
padding: 14px;
|
padding: 14px;
|
||||||
}
|
}
|
||||||
ha-textarea,
|
.description {
|
||||||
ha-textfield {
|
margin: 0;
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
@ -300,6 +236,9 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
.header:first-child {
|
||||||
|
margin-top: -16px;
|
||||||
|
}
|
||||||
.header .name {
|
.header .name {
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
@ -320,9 +259,6 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
.card-content {
|
.card-content {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
.card-content ha-textarea:first-child {
|
|
||||||
margin-top: -16px;
|
|
||||||
}
|
|
||||||
.settings-icon {
|
.settings-icon {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@ -340,6 +276,10 @@ export class HaManualAutomationEditor extends LitElement {
|
|||||||
border-top-right-radius: var(--ha-card-border-radius);
|
border-top-right-radius: var(--ha-card-border-radius);
|
||||||
border-top-left-radius: var(--ha-card-border-radius);
|
border-top-left-radius: var(--ha-card-border-radius);
|
||||||
}
|
}
|
||||||
|
ha-alert {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,8 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: false }) public trigger!: Trigger;
|
@property({ attribute: false }) public trigger!: Trigger;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public hideMenu = false;
|
||||||
|
|
||||||
@state() private _warnings?: string[];
|
@state() private _warnings?: string[];
|
||||||
|
|
||||||
@state() private _yamlMode = false;
|
@state() private _yamlMode = false;
|
||||||
@ -128,97 +130,110 @@ export default class HaAutomationTriggerRow extends LitElement {
|
|||||||
></ha-svg-icon>
|
></ha-svg-icon>
|
||||||
${capitalizeFirstLetter(describeTrigger(this.trigger, this.hass))}
|
${capitalizeFirstLetter(describeTrigger(this.trigger, this.hass))}
|
||||||
</h3>
|
</h3>
|
||||||
<ha-button-menu
|
|
||||||
slot="icons"
|
|
||||||
fixed
|
|
||||||
corner="BOTTOM_START"
|
|
||||||
@action=${this._handleAction}
|
|
||||||
@click=${preventDefault}
|
|
||||||
>
|
|
||||||
<ha-icon-button
|
|
||||||
slot="trigger"
|
|
||||||
.label=${this.hass.localize("ui.common.menu")}
|
|
||||||
.path=${mdiDotsVertical}
|
|
||||||
></ha-icon-button>
|
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<slot name="icons" slot="icons"></slot>
|
||||||
${this.hass.localize(
|
${this.hideMenu
|
||||||
"ui.panel.config.automation.editor.triggers.rename"
|
? ""
|
||||||
)}
|
: html`
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiRenameBox}></ha-svg-icon>
|
<ha-button-menu
|
||||||
</mwc-list-item>
|
slot="icons"
|
||||||
<mwc-list-item graphic="icon">
|
fixed
|
||||||
${this.hass.localize(
|
corner="BOTTOM_START"
|
||||||
"ui.panel.config.automation.editor.actions.duplicate"
|
@action=${this._handleAction}
|
||||||
)}
|
@click=${preventDefault}
|
||||||
<ha-svg-icon
|
>
|
||||||
slot="graphic"
|
<ha-icon-button
|
||||||
.path=${mdiContentDuplicate}
|
slot="trigger"
|
||||||
></ha-svg-icon>
|
.label=${this.hass.localize("ui.common.menu")}
|
||||||
</mwc-list-item>
|
.path=${mdiDotsVertical}
|
||||||
|
></ha-icon-button>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<mwc-list-item graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.triggers.edit_id"
|
"ui.panel.config.automation.editor.triggers.rename"
|
||||||
)}
|
)}
|
||||||
<ha-svg-icon slot="graphic" .path=${mdiIdentifier}></ha-svg-icon>
|
<ha-svg-icon
|
||||||
</mwc-list-item>
|
slot="graphic"
|
||||||
|
.path=${mdiRenameBox}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.duplicate"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiContentDuplicate}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.edit_id"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiIdentifier}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!supported} graphic="icon">
|
<li divider role="separator"></li>
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
|
||||||
${!yamlMode
|
|
||||||
? html`<ha-svg-icon
|
|
||||||
class="selected_menu_item"
|
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiCheck}
|
|
||||||
></ha-svg-icon>`
|
|
||||||
: ``}
|
|
||||||
</mwc-list-item>
|
|
||||||
|
|
||||||
<mwc-list-item .disabled=${!supported} graphic="icon">
|
<mwc-list-item .disabled=${!supported} graphic="icon">
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.edit_yaml"
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
)}
|
)}
|
||||||
${yamlMode
|
${!yamlMode
|
||||||
? html`<ha-svg-icon
|
? html`<ha-svg-icon
|
||||||
class="selected_menu_item"
|
class="selected_menu_item"
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${mdiCheck}
|
.path=${mdiCheck}
|
||||||
></ha-svg-icon>`
|
></ha-svg-icon>`
|
||||||
: ``}
|
: ``}
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
|
|
||||||
<li divider role="separator"></li>
|
<mwc-list-item .disabled=${!supported} graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.edit_yaml"
|
||||||
|
)}
|
||||||
|
${yamlMode
|
||||||
|
? html`<ha-svg-icon
|
||||||
|
class="selected_menu_item"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiCheck}
|
||||||
|
></ha-svg-icon>`
|
||||||
|
: ``}
|
||||||
|
</mwc-list-item>
|
||||||
|
|
||||||
<mwc-list-item graphic="icon">
|
<li divider role="separator"></li>
|
||||||
${this.trigger.enabled === false
|
|
||||||
? this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.enable"
|
|
||||||
)
|
|
||||||
: this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.disable"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
|
||||||
slot="graphic"
|
|
||||||
.path=${this.trigger.enabled === false
|
|
||||||
? mdiPlayCircleOutline
|
|
||||||
: mdiStopCircleOutline}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
<mwc-list-item class="warning" graphic="icon">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.automation.editor.actions.delete"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
|
||||||
class="warning"
|
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiDelete}
|
|
||||||
></ha-svg-icon>
|
|
||||||
</mwc-list-item>
|
|
||||||
</ha-button-menu>
|
|
||||||
|
|
||||||
|
<mwc-list-item graphic="icon">
|
||||||
|
${this.trigger.enabled === false
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.enable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.disable"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
slot="graphic"
|
||||||
|
.path=${this.trigger.enabled === false
|
||||||
|
? mdiPlayCircleOutline
|
||||||
|
: mdiStopCircleOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
<mwc-list-item class="warning" graphic="icon">
|
||||||
|
${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.actions.delete"
|
||||||
|
)}
|
||||||
|
<ha-svg-icon
|
||||||
|
class="warning"
|
||||||
|
slot="graphic"
|
||||||
|
.path=${mdiDelete}
|
||||||
|
></ha-svg-icon>
|
||||||
|
</mwc-list-item>
|
||||||
|
</ha-button-menu>
|
||||||
|
`}
|
||||||
<div
|
<div
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
"card-content": true,
|
"card-content": true,
|
||||||
|
@ -1,22 +1,26 @@
|
|||||||
import { repeat } from "lit/directives/repeat";
|
|
||||||
import { mdiPlus } from "@mdi/js";
|
|
||||||
import deepClone from "deep-clone-simple";
|
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import "@material/mwc-button";
|
import "@material/mwc-button";
|
||||||
|
import type { ActionDetail } from "@material/mwc-list";
|
||||||
|
import { mdiArrowDown, mdiArrowUp, mdiDrag, mdiPlus } from "@mdi/js";
|
||||||
|
import deepClone from "deep-clone-simple";
|
||||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import type { ActionDetail } from "@material/mwc-list";
|
import { repeat } from "lit/directives/repeat";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
import type { SortableEvent } from "sortablejs";
|
||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-svg-icon";
|
import { stringCompare } from "../../../../common/string/compare";
|
||||||
|
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
||||||
import "../../../../components/ha-button-menu";
|
import "../../../../components/ha-button-menu";
|
||||||
|
import type { HaSelect } from "../../../../components/ha-select";
|
||||||
|
import "../../../../components/ha-svg-icon";
|
||||||
import { Trigger } from "../../../../data/automation";
|
import { Trigger } from "../../../../data/automation";
|
||||||
import { TRIGGER_TYPES } from "../../../../data/trigger";
|
import { TRIGGER_TYPES } from "../../../../data/trigger";
|
||||||
|
import { sortableStyles } from "../../../../resources/ha-sortable-style";
|
||||||
|
import { SortableInstance } from "../../../../resources/sortable";
|
||||||
|
import { loadSortable } from "../../../../resources/sortable.ondemand";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import "./ha-automation-trigger-row";
|
import "./ha-automation-trigger-row";
|
||||||
import type HaAutomationTriggerRow from "./ha-automation-trigger-row";
|
import type HaAutomationTriggerRow from "./ha-automation-trigger-row";
|
||||||
import type { LocalizeFunc } from "../../../../common/translations/localize";
|
|
||||||
import { stringCompare } from "../../../../common/string/compare";
|
|
||||||
import type { HaSelect } from "../../../../components/ha-select";
|
|
||||||
import "./types/ha-automation-trigger-calendar";
|
import "./types/ha-automation-trigger-calendar";
|
||||||
import "./types/ha-automation-trigger-device";
|
import "./types/ha-automation-trigger-device";
|
||||||
import "./types/ha-automation-trigger-event";
|
import "./types/ha-automation-trigger-event";
|
||||||
@ -39,49 +43,93 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
|
|
||||||
@property() public triggers!: Trigger[];
|
@property() public triggers!: Trigger[];
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public reOrderMode = false;
|
||||||
|
|
||||||
private _focusLastTriggerOnChange = false;
|
private _focusLastTriggerOnChange = false;
|
||||||
|
|
||||||
private _triggerKeys = new WeakMap<Trigger, string>();
|
private _triggerKeys = new WeakMap<Trigger, string>();
|
||||||
|
|
||||||
|
private _sortable?: SortableInstance;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
${repeat(
|
<div class="triggers">
|
||||||
this.triggers,
|
${repeat(
|
||||||
(trigger) => this._getKey(trigger),
|
this.triggers,
|
||||||
(trg, idx) => html`
|
(trigger) => this._getKey(trigger),
|
||||||
<ha-automation-trigger-row
|
(trg, idx) => html`
|
||||||
.index=${idx}
|
<ha-automation-trigger-row
|
||||||
.trigger=${trg}
|
.index=${idx}
|
||||||
@duplicate=${this._duplicateTrigger}
|
.trigger=${trg}
|
||||||
@value-changed=${this._triggerChanged}
|
.hideMenu=${this.reOrderMode}
|
||||||
.hass=${this.hass}
|
@duplicate=${this._duplicateTrigger}
|
||||||
></ha-automation-trigger-row>
|
@value-changed=${this._triggerChanged}
|
||||||
`
|
.hass=${this.hass}
|
||||||
)}
|
>
|
||||||
<ha-button-menu @action=${this._addTrigger}>
|
${this.reOrderMode
|
||||||
<mwc-button
|
? html`
|
||||||
slot="trigger"
|
<ha-icon-button
|
||||||
outlined
|
.index=${idx}
|
||||||
.label=${this.hass.localize(
|
slot="icons"
|
||||||
"ui.panel.config.automation.editor.triggers.add"
|
.label=${this.hass.localize(
|
||||||
)}
|
"ui.panel.config.automation.editor.move_up"
|
||||||
>
|
)}
|
||||||
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
.path=${mdiArrowUp}
|
||||||
</mwc-button>
|
@click=${this._moveUp}
|
||||||
${this._processedTypes(this.hass.localize).map(
|
.disabled=${idx === 0}
|
||||||
([opt, label, icon]) => html`
|
></ha-icon-button>
|
||||||
<mwc-list-item .value=${opt} aria-label=${label} graphic="icon">
|
<ha-icon-button
|
||||||
${label}<ha-svg-icon slot="graphic" .path=${icon}></ha-svg-icon
|
.index=${idx}
|
||||||
></mwc-list-item>
|
slot="icons"
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.move_down"
|
||||||
|
)}
|
||||||
|
.path=${mdiArrowDown}
|
||||||
|
@click=${this._moveDown}
|
||||||
|
.disabled=${idx === this.triggers.length - 1}
|
||||||
|
></ha-icon-button>
|
||||||
|
<div class="handle" slot="icons">
|
||||||
|
<ha-svg-icon .path=${mdiDrag}></ha-svg-icon>
|
||||||
|
</div>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
</ha-automation-trigger-row>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</ha-button-menu>
|
</div>
|
||||||
|
<ha-button-menu @action=${this._addTrigger}>
|
||||||
|
<mwc-button
|
||||||
|
slot="trigger"
|
||||||
|
outlined
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.add"
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ha-svg-icon .path=${mdiPlus} slot="icon"></ha-svg-icon>
|
||||||
|
</mwc-button>
|
||||||
|
${this._processedTypes(this.hass.localize).map(
|
||||||
|
([opt, label, icon]) => html`
|
||||||
|
<mwc-list-item .value=${opt} aria-label=${label} graphic="icon">
|
||||||
|
${label}<ha-svg-icon slot="graphic" .path=${icon}></ha-svg-icon
|
||||||
|
></mwc-list-item>
|
||||||
|
`
|
||||||
|
)}
|
||||||
|
</ha-button-menu>
|
||||||
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
|
|
||||||
|
if (changedProps.has("reOrderMode")) {
|
||||||
|
if (this.reOrderMode) {
|
||||||
|
this._createSortable();
|
||||||
|
} else {
|
||||||
|
this._destroySortable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (changedProps.has("triggers") && this._focusLastTriggerOnChange) {
|
if (changedProps.has("triggers") && this._focusLastTriggerOnChange) {
|
||||||
this._focusLastTriggerOnChange = false;
|
this._focusLastTriggerOnChange = false;
|
||||||
|
|
||||||
@ -96,6 +144,36 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async _createSortable() {
|
||||||
|
const Sortable = await loadSortable();
|
||||||
|
this._sortable = new Sortable(
|
||||||
|
this.shadowRoot!.querySelector(".triggers")!,
|
||||||
|
{
|
||||||
|
animation: 150,
|
||||||
|
fallbackClass: "sortable-fallback",
|
||||||
|
handle: ".handle",
|
||||||
|
onChoose: (evt: SortableEvent) => {
|
||||||
|
(evt.item as any).placeholder =
|
||||||
|
document.createComment("sort-placeholder");
|
||||||
|
evt.item.after((evt.item as any).placeholder);
|
||||||
|
},
|
||||||
|
onEnd: (evt: SortableEvent) => {
|
||||||
|
// put back in original location
|
||||||
|
if ((evt.item as any).placeholder) {
|
||||||
|
(evt.item as any).placeholder.replaceWith(evt.item);
|
||||||
|
delete (evt.item as any).placeholder;
|
||||||
|
}
|
||||||
|
this._dragged(evt);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _destroySortable() {
|
||||||
|
this._sortable?.destroy();
|
||||||
|
this._sortable = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private _getKey(action: Trigger) {
|
private _getKey(action: Trigger) {
|
||||||
if (!this._triggerKeys.has(action)) {
|
if (!this._triggerKeys.has(action)) {
|
||||||
this._triggerKeys.set(action, Math.random().toString());
|
this._triggerKeys.set(action, Math.random().toString());
|
||||||
@ -122,6 +200,30 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
fireEvent(this, "value-changed", { value: triggers });
|
fireEvent(this, "value-changed", { value: triggers });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _moveUp(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = index - 1;
|
||||||
|
this._move(index, newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _moveDown(ev) {
|
||||||
|
const index = (ev.target as any).index;
|
||||||
|
const newIndex = index + 1;
|
||||||
|
this._move(index, newIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _dragged(ev: SortableEvent): void {
|
||||||
|
if (ev.oldIndex === ev.newIndex) return;
|
||||||
|
this._move(ev.oldIndex!, ev.newIndex!);
|
||||||
|
}
|
||||||
|
|
||||||
|
private _move(index: number, newIndex: number) {
|
||||||
|
const triggers = this.triggers.concat();
|
||||||
|
const trigger = triggers.splice(index, 1)[0];
|
||||||
|
triggers.splice(newIndex, 0, trigger);
|
||||||
|
fireEvent(this, "value-changed", { value: triggers });
|
||||||
|
}
|
||||||
|
|
||||||
private _triggerChanged(ev: CustomEvent) {
|
private _triggerChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const triggers = [...this.triggers];
|
const triggers = [...this.triggers];
|
||||||
@ -166,16 +268,27 @@ export default class HaAutomationTrigger extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return [
|
||||||
ha-automation-trigger-row {
|
sortableStyles,
|
||||||
display: block;
|
css`
|
||||||
margin-bottom: 16px;
|
ha-automation-trigger-row {
|
||||||
scroll-margin-top: 48px;
|
display: block;
|
||||||
}
|
margin-bottom: 16px;
|
||||||
ha-svg-icon {
|
scroll-margin-top: 48px;
|
||||||
height: 20px;
|
}
|
||||||
}
|
ha-svg-icon {
|
||||||
`;
|
height: 20px;
|
||||||
|
}
|
||||||
|
.handle {
|
||||||
|
cursor: move;
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
.handle ha-svg-icon {
|
||||||
|
pointer-events: none;
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ export class HaTagTrigger extends LitElement implements TriggerElement {
|
|||||||
|
|
||||||
private _tagChanged(ev) {
|
private _tagChanged(ev) {
|
||||||
if (
|
if (
|
||||||
!ev.detail.value ||
|
!ev.target.value ||
|
||||||
!this._tags ||
|
!this._tags ||
|
||||||
this.trigger.tag_id === ev.detail.value
|
this.trigger.tag_id === ev.target.value
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -60,12 +60,11 @@ import {
|
|||||||
import "../../../layouts/hass-error-screen";
|
import "../../../layouts/hass-error-screen";
|
||||||
import "../../../layouts/hass-tabs-subpage";
|
import "../../../layouts/hass-tabs-subpage";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import type { HomeAssistant, Route } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import { brandsUrl } from "../../../util/brands-url";
|
import { brandsUrl } from "../../../util/brands-url";
|
||||||
import { fileDownload } from "../../../util/file_download";
|
import { fileDownload } from "../../../util/file_download";
|
||||||
import "../../logbook/ha-logbook";
|
import "../../logbook/ha-logbook";
|
||||||
import "../ha-config-section";
|
import "../ha-config-section";
|
||||||
import { configSections } from "../ha-panel-config";
|
|
||||||
import "./device-detail/ha-device-entities-card";
|
import "./device-detail/ha-device-entities-card";
|
||||||
import "./device-detail/ha-device-info-card";
|
import "./device-detail/ha-device-info-card";
|
||||||
import { showDeviceAutomationDialog } from "./device-detail/show-dialog-device-automation";
|
import { showDeviceAutomationDialog } from "./device-detail/show-dialog-device-automation";
|
||||||
@ -73,6 +72,7 @@ import {
|
|||||||
loadDeviceRegistryDetailDialog,
|
loadDeviceRegistryDetailDialog,
|
||||||
showDeviceRegistryDetailDialog,
|
showDeviceRegistryDetailDialog,
|
||||||
} from "./device-registry-detail/show-dialog-device-registry-detail";
|
} from "./device-registry-detail/show-dialog-device-registry-detail";
|
||||||
|
import "../../../layouts/hass-subpage";
|
||||||
|
|
||||||
export interface EntityRegistryStateEntry extends EntityRegistryEntry {
|
export interface EntityRegistryStateEntry extends EntityRegistryEntry {
|
||||||
stateName?: string | null;
|
stateName?: string | null;
|
||||||
@ -96,23 +96,21 @@ export interface DeviceAlert {
|
|||||||
export class HaConfigDevicePage extends LitElement {
|
export class HaConfigDevicePage extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property() public devices!: DeviceRegistryEntry[];
|
@property({ attribute: false }) public devices!: DeviceRegistryEntry[];
|
||||||
|
|
||||||
@property() public entries!: ConfigEntry[];
|
@property({ attribute: false }) public entries!: ConfigEntry[];
|
||||||
|
|
||||||
@property() public entities!: EntityRegistryEntry[];
|
@property({ attribute: false }) public entities!: EntityRegistryEntry[];
|
||||||
|
|
||||||
@property() public areas!: AreaRegistryEntry[];
|
@property({ attribute: false }) public areas!: AreaRegistryEntry[];
|
||||||
|
|
||||||
@property() public deviceId!: string;
|
@property() public deviceId!: string;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
@property({ type: Boolean, reflect: true }) public narrow!: boolean;
|
||||||
|
|
||||||
@property() public isWide!: boolean;
|
@property({ type: Boolean }) public isWide!: boolean;
|
||||||
|
|
||||||
@property() public showAdvanced!: boolean;
|
@property({ type: Boolean }) public showAdvanced!: boolean;
|
||||||
|
|
||||||
@property() public route!: Route;
|
|
||||||
|
|
||||||
@state() private _related?: RelatedResult;
|
@state() private _related?: RelatedResult;
|
||||||
|
|
||||||
@ -609,16 +607,12 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
: "";
|
: "";
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.tabs=${configSections.devices}
|
.header=${deviceName}
|
||||||
.route=${this.route}
|
|
||||||
>
|
>
|
||||||
${
|
|
||||||
this.narrow
|
|
||||||
? html`
|
|
||||||
<span slot="header">${deviceName}</span>
|
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="toolbar-icon"
|
slot="toolbar-icon"
|
||||||
.path=${mdiPencil}
|
.path=${mdiPencil}
|
||||||
@ -627,39 +621,20 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
"ui.panel.config.devices.edit_settings"
|
"ui.panel.config.devices.edit_settings"
|
||||||
)}
|
)}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
`
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="header fullwidth">
|
<div class="header fullwidth">
|
||||||
${
|
${
|
||||||
this.narrow
|
area
|
||||||
? ""
|
? html`<div class="header-name">
|
||||||
: html`
|
<a href="/config/areas/area/${area.area_id}"
|
||||||
<div class="header-name">
|
>${this.hass.localize(
|
||||||
<div>
|
"ui.panel.config.integrations.config_entry.area",
|
||||||
<h1>${deviceName}</h1>
|
"area",
|
||||||
${area
|
area.name || "Unnamed Area"
|
||||||
? html`
|
)}</a
|
||||||
<a href="/config/areas/area/${area.area_id}"
|
>
|
||||||
>${this.hass.localize(
|
</div>`
|
||||||
"ui.panel.config.integrations.config_entry.area",
|
: ""
|
||||||
"area",
|
|
||||||
area.name || "Unnamed Area"
|
|
||||||
)}</a
|
|
||||||
>
|
|
||||||
`
|
|
||||||
: ""}
|
|
||||||
</div>
|
|
||||||
<ha-icon-button
|
|
||||||
.path=${mdiPencil}
|
|
||||||
@click=${this._showSettings}
|
|
||||||
.label=${this.hass.localize(
|
|
||||||
"ui.panel.config.devices.edit_settings"
|
|
||||||
)}
|
|
||||||
></ha-icon-button>
|
|
||||||
</div>
|
|
||||||
`
|
|
||||||
}
|
}
|
||||||
<div class="header-right">
|
<div class="header-right">
|
||||||
${
|
${
|
||||||
@ -859,7 +834,7 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</ha-config-section>
|
</ha-config-section>
|
||||||
</hass-tabs-subpage> `;
|
</hass-subpage> `;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _getDiagnosticButtons(requestId: number): Promise<void> {
|
private async _getDiagnosticButtons(requestId: number): Promise<void> {
|
||||||
|
@ -319,7 +319,7 @@ export const configSections: { [name: string]: PageNavigation[] } = {
|
|||||||
translationKey: "hardware",
|
translationKey: "hardware",
|
||||||
iconPath: mdiMemory,
|
iconPath: mdiMemory,
|
||||||
iconColor: "#301A8E",
|
iconColor: "#301A8E",
|
||||||
component: "hassio",
|
components: ["hassio", "hardware"],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
about: [
|
about: [
|
||||||
|
@ -284,38 +284,38 @@ class HaConfigHardware extends SubscribeMixin(LitElement) {
|
|||||||
</ha-card>
|
</ha-card>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
|
${this._systemStatusData
|
||||||
<ha-card outlined>
|
? html` <ha-card outlined>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="title">
|
<div class="title">
|
||||||
${this.hass.localize("ui.panel.config.hardware.processor")}
|
${this.hass.localize(
|
||||||
</div>
|
"ui.panel.config.hardware.processor"
|
||||||
<div class="value">
|
)}
|
||||||
${this._systemStatusData?.cpu_percent || "-"}%
|
</div>
|
||||||
</div>
|
<div class="value">
|
||||||
</div>
|
${this._systemStatusData.cpu_percent || "-"}%
|
||||||
<div class="card-content">
|
</div>
|
||||||
<ha-chart-base
|
</div>
|
||||||
.data=${{
|
<div class="card-content">
|
||||||
datasets: [
|
<ha-chart-base
|
||||||
{
|
.data=${{
|
||||||
...DATA_SET_CONFIG,
|
datasets: [
|
||||||
data: this._cpuEntries,
|
{
|
||||||
},
|
...DATA_SET_CONFIG,
|
||||||
],
|
data: this._cpuEntries,
|
||||||
}}
|
},
|
||||||
.options=${this._chartOptions}
|
],
|
||||||
></ha-chart-base>
|
}}
|
||||||
</div>
|
.options=${this._chartOptions}
|
||||||
</ha-card>
|
></ha-chart-base>
|
||||||
<ha-card outlined>
|
</div>
|
||||||
<div class="header">
|
</ha-card>
|
||||||
<div class="title">
|
<ha-card outlined>
|
||||||
${this.hass.localize("ui.panel.config.hardware.memory")}
|
<div class="header">
|
||||||
</div>
|
<div class="title">
|
||||||
<div class="value">
|
${this.hass.localize("ui.panel.config.hardware.memory")}
|
||||||
${this._systemStatusData
|
</div>
|
||||||
? html`
|
<div class="value">
|
||||||
${round(this._systemStatusData.memory_used_mb / 1024, 1)}
|
${round(this._systemStatusData.memory_used_mb / 1024, 1)}
|
||||||
GB /
|
GB /
|
||||||
${round(
|
${round(
|
||||||
@ -325,24 +325,23 @@ class HaConfigHardware extends SubscribeMixin(LitElement) {
|
|||||||
0
|
0
|
||||||
)}
|
)}
|
||||||
GB
|
GB
|
||||||
`
|
</div>
|
||||||
: "- GB / - GB"}
|
</div>
|
||||||
</div>
|
<div class="card-content">
|
||||||
</div>
|
<ha-chart-base
|
||||||
<div class="card-content">
|
.data=${{
|
||||||
<ha-chart-base
|
datasets: [
|
||||||
.data=${{
|
{
|
||||||
datasets: [
|
...DATA_SET_CONFIG,
|
||||||
{
|
data: this._memoryEntries,
|
||||||
...DATA_SET_CONFIG,
|
},
|
||||||
data: this._memoryEntries,
|
],
|
||||||
},
|
}}
|
||||||
],
|
.options=${this._chartOptions}
|
||||||
}}
|
></ha-chart-base>
|
||||||
.options=${this._chartOptions}
|
</div>
|
||||||
></ha-chart-base>
|
</ha-card>`
|
||||||
</div>
|
: ""}
|
||||||
</ha-card>
|
|
||||||
</div>
|
</div>
|
||||||
</hass-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
|
@ -60,7 +60,7 @@ class ZHAConfigDashboardRouter extends HassRouterPage {
|
|||||||
} else if (this._currentPage === "device") {
|
} else if (this._currentPage === "device") {
|
||||||
el.ieee = this.routeTail.path.substr(1);
|
el.ieee = this.routeTail.path.substr(1);
|
||||||
} else if (this._currentPage === "visualization") {
|
} else if (this._currentPage === "visualization") {
|
||||||
el.zoomedDeviceId = this.routeTail.path.substr(1);
|
el.zoomedDeviceIdFromURL = this.routeTail.path.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
|
@ -37,7 +37,10 @@ export class ZHANetworkVisualizationPage extends LitElement {
|
|||||||
@property({ type: Boolean }) public isWide!: boolean;
|
@property({ type: Boolean }) public isWide!: boolean;
|
||||||
|
|
||||||
@property()
|
@property()
|
||||||
public zoomedDeviceId?: string;
|
public zoomedDeviceIdFromURL?: string;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
private zoomedDeviceId?: string;
|
||||||
|
|
||||||
@query("#visualization", true)
|
@query("#visualization", true)
|
||||||
private _visualization?: HTMLElement;
|
private _visualization?: HTMLElement;
|
||||||
@ -64,6 +67,11 @@ export class ZHANetworkVisualizationPage extends LitElement {
|
|||||||
protected firstUpdated(changedProperties: PropertyValues): void {
|
protected firstUpdated(changedProperties: PropertyValues): void {
|
||||||
super.firstUpdated(changedProperties);
|
super.firstUpdated(changedProperties);
|
||||||
|
|
||||||
|
// prevent zoomedDeviceIdFromURL from being restored to zoomedDeviceId after the user clears it
|
||||||
|
if (this.zoomedDeviceIdFromURL) {
|
||||||
|
this.zoomedDeviceId = this.zoomedDeviceIdFromURL;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.hass) {
|
if (this.hass) {
|
||||||
this._fetchData();
|
this._fetchData();
|
||||||
}
|
}
|
||||||
|
@ -11,9 +11,13 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent, HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import { DataTableColumnContainer } from "../../../components/data-table/ha-data-table";
|
import { navigate } from "../../../common/navigate";
|
||||||
|
import {
|
||||||
|
DataTableColumnContainer,
|
||||||
|
RowClickedEvent,
|
||||||
|
} from "../../../components/data-table/ha-data-table";
|
||||||
import "../../../components/ha-button-related-filter-menu";
|
import "../../../components/ha-button-related-filter-menu";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
@ -165,6 +169,8 @@ class HaSceneDashboard extends LitElement {
|
|||||||
)}
|
)}
|
||||||
@clear-filter=${this._clearFilter}
|
@clear-filter=${this._clearFilter}
|
||||||
hasFab
|
hasFab
|
||||||
|
clickable
|
||||||
|
@row-click=${this._handleRowClicked}
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="toolbar-icon"
|
slot="toolbar-icon"
|
||||||
@ -196,6 +202,14 @@ class HaSceneDashboard extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
|
||||||
|
const scene = this.scenes.find((a) => a.entity_id === ev.detail.id);
|
||||||
|
|
||||||
|
if (scene?.attributes.id) {
|
||||||
|
navigate(`/config/scene/edit/${scene?.attributes.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _relatedFilterChanged(ev: CustomEvent) {
|
private _relatedFilterChanged(ev: CustomEvent) {
|
||||||
this._filterValue = ev.detail.value;
|
this._filterValue = ev.detail.value;
|
||||||
if (!this._filterValue) {
|
if (!this._filterValue) {
|
||||||
|
@ -63,13 +63,13 @@ import {
|
|||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
} from "../../../dialogs/generic/show-dialog-box";
|
} from "../../../dialogs/generic/show-dialog-box";
|
||||||
|
import "../../../layouts/hass-subpage";
|
||||||
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
||||||
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../../../mixins/subscribe-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant, Route } from "../../../types";
|
import { HomeAssistant, Route } from "../../../types";
|
||||||
import { showToast } from "../../../util/toast";
|
import { showToast } from "../../../util/toast";
|
||||||
import "../ha-config-section";
|
import "../ha-config-section";
|
||||||
import { configSections } from "../ha-panel-config";
|
|
||||||
|
|
||||||
interface DeviceEntities {
|
interface DeviceEntities {
|
||||||
id: string;
|
id: string;
|
||||||
@ -214,17 +214,16 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
this._deviceEntityLookup,
|
this._deviceEntityLookup,
|
||||||
this._deviceRegistryEntries
|
this._deviceRegistryEntries
|
||||||
);
|
);
|
||||||
const name = this._scene
|
|
||||||
? computeStateName(this._scene)
|
|
||||||
: this.hass.localize("ui.panel.config.scene.editor.default_name");
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.backCallback=${this._backTapped}
|
.backCallback=${this._backTapped}
|
||||||
.tabs=${configSections.automations}
|
.header=${this._scene
|
||||||
|
? computeStateName(this._scene)
|
||||||
|
: this.hass.localize("ui.panel.config.scene.editor.default_name")}
|
||||||
>
|
>
|
||||||
<ha-button-menu
|
<ha-button-menu
|
||||||
corner="BOTTOM_START"
|
corner="BOTTOM_START"
|
||||||
@ -272,7 +271,6 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
${this._errors ? html` <div class="errors">${this._errors}</div> ` : ""}
|
${this._errors ? html` <div class="errors">${this._errors}</div> ` : ""}
|
||||||
${this.narrow ? html` <span slot="header">${name}</span> ` : ""}
|
|
||||||
<div
|
<div
|
||||||
id="root"
|
id="root"
|
||||||
class=${classMap({
|
class=${classMap({
|
||||||
@ -281,15 +279,7 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
>
|
>
|
||||||
${this._config
|
${this._config
|
||||||
? html`
|
? html`
|
||||||
<ha-config-section vertical .isWide=${this.isWide}>
|
<div class="container">
|
||||||
${!this.narrow
|
|
||||||
? html` <span slot="header">${name}</span> `
|
|
||||||
: ""}
|
|
||||||
<div slot="introduction">
|
|
||||||
${this.hass.localize(
|
|
||||||
"ui.panel.config.scene.editor.introduction"
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<ha-card outlined>
|
<ha-card outlined>
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<ha-textfield
|
<ha-textfield
|
||||||
@ -322,7 +312,7 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
</ha-area-picker>
|
</ha-area-picker>
|
||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
</ha-config-section>
|
</div>
|
||||||
|
|
||||||
<ha-config-section vertical .isWide=${this.isWide}>
|
<ha-config-section vertical .isWide=${this.isWide}>
|
||||||
<div slot="header">
|
<div slot="header">
|
||||||
@ -486,7 +476,7 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
>
|
>
|
||||||
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
|
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
|
||||||
</ha-fab>
|
</ha-fab>
|
||||||
</hass-tabs-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -963,6 +953,16 @@ export class HaSceneEditor extends SubscribeMixin(
|
|||||||
ha-card {
|
ha-card {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
.container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
margin-top: 24px;
|
||||||
|
}
|
||||||
|
.container > * {
|
||||||
|
max-width: 1040px;
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
|
||||||
.errors {
|
.errors {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { property, state, query } 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 memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { computeObjectId } from "../../../common/entity/compute_object_id";
|
import { computeObjectId } from "../../../common/entity/compute_object_id";
|
||||||
@ -51,13 +51,13 @@ import {
|
|||||||
} from "../../../data/script";
|
} from "../../../data/script";
|
||||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
import "../../../layouts/ha-app-layout";
|
import "../../../layouts/ha-app-layout";
|
||||||
|
import "../../../layouts/hass-subpage";
|
||||||
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import type { HomeAssistant, Route } from "../../../types";
|
import type { HomeAssistant, Route } from "../../../types";
|
||||||
import { documentationUrl } from "../../../util/documentation-url";
|
import { documentationUrl } from "../../../util/documentation-url";
|
||||||
import { showToast } from "../../../util/toast";
|
import { showToast } from "../../../util/toast";
|
||||||
import { HaDeviceAction } from "../automation/action/types/ha-automation-action-device_id";
|
import { HaDeviceAction } from "../automation/action/types/ha-automation-action-device_id";
|
||||||
import { configSections } from "../ha-panel-config";
|
|
||||||
import "./blueprint-script-editor";
|
import "./blueprint-script-editor";
|
||||||
|
|
||||||
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
||||||
@ -168,12 +168,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<hass-tabs-subpage
|
<hass-subpage
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.route=${this.route}
|
.route=${this.route}
|
||||||
.backCallback=${this._backTapped}
|
.backCallback=${this._backTapped}
|
||||||
.tabs=${configSections.automations}
|
.header=${!this._config?.alias ? "" : this._config.alias}
|
||||||
>
|
>
|
||||||
<ha-button-menu
|
<ha-button-menu
|
||||||
corner="BOTTOM_START"
|
corner="BOTTOM_START"
|
||||||
@ -192,7 +192,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
"ui.panel.config.automation.editor.edit_ui"
|
"ui.panel.config.automation.editor.edit_ui"
|
||||||
)}
|
)}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
?activated=${this._mode === "gui"}
|
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
${this.hass.localize("ui.panel.config.automation.editor.edit_ui")}
|
||||||
${this._mode === "gui"
|
${this._mode === "gui"
|
||||||
@ -228,13 +227,11 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
.disabled=${!this.scriptEntityId}
|
.disabled=${!this.scriptEntityId}
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.script.picker.duplicate_script"
|
"ui.panel.config.script.picker.duplicate"
|
||||||
)}
|
)}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize("ui.panel.config.script.picker.duplicate")}
|
||||||
"ui.panel.config.script.picker.duplicate_script"
|
|
||||||
)}
|
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
.path=${mdiContentDuplicate}
|
.path=${mdiContentDuplicate}
|
||||||
@ -244,12 +241,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
.disabled=${!this.scriptEntityId}
|
.disabled=${!this.scriptEntityId}
|
||||||
aria-label=${this.hass.localize(
|
aria-label=${this.hass.localize(
|
||||||
"ui.panel.config.script.editor.delete_script"
|
"ui.panel.config.script.picker.delete"
|
||||||
)}
|
)}
|
||||||
class=${classMap({ warning: Boolean(this.scriptEntityId) })}
|
class=${classMap({ warning: Boolean(this.scriptEntityId) })}
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
>
|
>
|
||||||
${this.hass.localize("ui.panel.config.script.editor.delete_script")}
|
${this.hass.localize("ui.panel.config.script.picker.delete")}
|
||||||
<ha-svg-icon
|
<ha-svg-icon
|
||||||
class=${classMap({ warning: Boolean(this.scriptEntityId) })}
|
class=${classMap({ warning: Boolean(this.scriptEntityId) })}
|
||||||
slot="graphic"
|
slot="graphic"
|
||||||
@ -258,9 +255,6 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
</ha-svg-icon>
|
</ha-svg-icon>
|
||||||
</mwc-list-item>
|
</mwc-list-item>
|
||||||
</ha-button-menu>
|
</ha-button-menu>
|
||||||
${this.narrow
|
|
||||||
? html`<span slot="header">${this._config?.alias}</span>`
|
|
||||||
: ""}
|
|
||||||
<div
|
<div
|
||||||
class="content ${classMap({
|
class="content ${classMap({
|
||||||
"yaml-mode": this._mode === "yaml",
|
"yaml-mode": this._mode === "yaml",
|
||||||
@ -418,7 +412,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
>
|
>
|
||||||
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
|
<ha-svg-icon slot="icon" .path=${mdiContentSave}></ha-svg-icon>
|
||||||
</ha-fab>
|
</ha-fab>
|
||||||
</hass-tabs-subpage>
|
</hass-subpage>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,14 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { formatDateTime } from "../../../common/datetime/format_date_time";
|
import { formatDateTime } from "../../../common/datetime/format_date_time";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent, HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
|
import { navigate } from "../../../common/navigate";
|
||||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||||
import { DataTableColumnContainer } from "../../../components/data-table/ha-data-table";
|
import {
|
||||||
|
DataTableColumnContainer,
|
||||||
|
RowClickedEvent,
|
||||||
|
} from "../../../components/data-table/ha-data-table";
|
||||||
import "../../../components/ha-button-related-filter-menu";
|
import "../../../components/ha-button-related-filter-menu";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
@ -191,6 +195,8 @@ class HaScriptPicker extends LitElement {
|
|||||||
)}
|
)}
|
||||||
@clear-filter=${this._clearFilter}
|
@clear-filter=${this._clearFilter}
|
||||||
hasFab
|
hasFab
|
||||||
|
clickable
|
||||||
|
@row-click=${this._handleRowClicked}
|
||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
slot="toolbar-icon"
|
slot="toolbar-icon"
|
||||||
@ -241,6 +247,10 @@ class HaScriptPicker extends LitElement {
|
|||||||
this._filterValue = undefined;
|
this._filterValue = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _handleRowClicked(ev: HASSDomEvent<RowClickedEvent>) {
|
||||||
|
navigate(`/config/script/edit/${ev.detail.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
private _runScript = async (ev) => {
|
private _runScript = async (ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const script = ev.currentTarget.script as HassEntity;
|
const script = ev.currentTarget.script as HassEntity;
|
||||||
|
@ -34,6 +34,8 @@ import {
|
|||||||
} from "../../resources/styles";
|
} from "../../resources/styles";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
import { brandsUrl } from "../../util/brands-url";
|
import { brandsUrl } from "../../util/brands-url";
|
||||||
|
import "../../components/ha-icon-next";
|
||||||
|
import { navigate } from "../../common/navigate";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
@ -156,8 +158,26 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
})
|
})
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
const traceContext =
|
||||||
|
triggerDomains.includes(item.domain!) &&
|
||||||
|
item.context_id! in this.traceContexts
|
||||||
|
? this.traceContexts[item.context_id!]
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const hasTrace = traceContext !== undefined;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="entry-container">
|
<div
|
||||||
|
class="entry-container ${classMap({ clickable: hasTrace })}"
|
||||||
|
.traceLink=${traceContext
|
||||||
|
? `/config/${traceContext.domain}/trace/${
|
||||||
|
traceContext.domain === "script"
|
||||||
|
? `script.${traceContext.item_id}`
|
||||||
|
: traceContext.item_id
|
||||||
|
}?run_id=${traceContext.run_id}`
|
||||||
|
: undefined}
|
||||||
|
@click=${this._handleClick}
|
||||||
|
>
|
||||||
${index === 0 ||
|
${index === 0 ||
|
||||||
(item?.when &&
|
(item?.when &&
|
||||||
previous?.when &&
|
previous?.when &&
|
||||||
@ -186,15 +206,16 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
<div class="message-relative_time">
|
<div class="message-relative_time">
|
||||||
<div class="message">
|
<div class="message">
|
||||||
${!this.noName // Used for more-info panel (single entity case)
|
${!this.noName // Used for more-info panel (single entity case)
|
||||||
? this._renderEntity(item.entity_id, item.name)
|
? this._renderEntity(item.entity_id, item.name, hasTrace)
|
||||||
: ""}
|
: ""}
|
||||||
${this._renderMessage(
|
${this._renderMessage(
|
||||||
item,
|
item,
|
||||||
seenEntityIds,
|
seenEntityIds,
|
||||||
domain,
|
domain,
|
||||||
historicStateObj
|
historicStateObj,
|
||||||
|
hasTrace
|
||||||
)}
|
)}
|
||||||
${this._renderContextMessage(item, seenEntityIds)}
|
${this._renderContextMessage(item, seenEntityIds, hasTrace)}
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary">
|
<div class="secondary">
|
||||||
<span
|
<span
|
||||||
@ -210,33 +231,15 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
capitalize
|
capitalize
|
||||||
></ha-relative-time>
|
></ha-relative-time>
|
||||||
${item.context_user_id ? html`${this._renderUser(item)}` : ""}
|
${item.context_user_id ? html`${this._renderUser(item)}` : ""}
|
||||||
${triggerDomains.includes(item.domain!) &&
|
${hasTrace
|
||||||
item.context_id! in this.traceContexts
|
? `- ${this.hass.localize(
|
||||||
? html`
|
"ui.components.logbook.show_trace"
|
||||||
-
|
)}`
|
||||||
<a
|
|
||||||
href=${`/config/${
|
|
||||||
this.traceContexts[item.context_id!].domain
|
|
||||||
}/trace/${
|
|
||||||
this.traceContexts[item.context_id!].domain ===
|
|
||||||
"script"
|
|
||||||
? `script.${
|
|
||||||
this.traceContexts[item.context_id!].item_id
|
|
||||||
}`
|
|
||||||
: this.traceContexts[item.context_id!].item_id
|
|
||||||
}?run_id=${
|
|
||||||
this.traceContexts[item.context_id!].run_id
|
|
||||||
}`}
|
|
||||||
@click=${this._close}
|
|
||||||
>${this.hass.localize(
|
|
||||||
"ui.components.logbook.show_trace"
|
|
||||||
)}</a
|
|
||||||
>
|
|
||||||
`
|
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
${hasTrace ? html`<ha-icon-next></ha-icon-next>` : ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -258,7 +261,8 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
item: LogbookEntry,
|
item: LogbookEntry,
|
||||||
seenEntityIds: string[],
|
seenEntityIds: string[],
|
||||||
domain?: string,
|
domain?: string,
|
||||||
historicStateObj?: HassEntity
|
historicStateObj?: HassEntity,
|
||||||
|
noLink?: boolean
|
||||||
) {
|
) {
|
||||||
if (item.entity_id) {
|
if (item.entity_id) {
|
||||||
if (item.state) {
|
if (item.state) {
|
||||||
@ -291,7 +295,8 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
? stripEntityId(message, item.context_entity_id)
|
? stripEntityId(message, item.context_entity_id)
|
||||||
: message,
|
: message,
|
||||||
seenEntityIds,
|
seenEntityIds,
|
||||||
undefined
|
undefined,
|
||||||
|
noLink
|
||||||
)
|
)
|
||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
@ -307,7 +312,8 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
|
|
||||||
private _renderUnseenContextSourceEntity(
|
private _renderUnseenContextSourceEntity(
|
||||||
item: LogbookEntry,
|
item: LogbookEntry,
|
||||||
seenEntityIds: string[]
|
seenEntityIds: string[],
|
||||||
|
noLink: boolean
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
!item.context_entity_id ||
|
!item.context_entity_id ||
|
||||||
@ -320,11 +326,16 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
// described event.
|
// described event.
|
||||||
return html` (${this._renderEntity(
|
return html` (${this._renderEntity(
|
||||||
item.context_entity_id,
|
item.context_entity_id,
|
||||||
item.context_entity_id_name
|
item.context_entity_id_name,
|
||||||
|
noLink
|
||||||
)})`;
|
)})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderContextMessage(item: LogbookEntry, seenEntityIds: string[]) {
|
private _renderContextMessage(
|
||||||
|
item: LogbookEntry,
|
||||||
|
seenEntityIds: string[],
|
||||||
|
noLink: boolean
|
||||||
|
) {
|
||||||
// State change
|
// State change
|
||||||
if (item.context_state) {
|
if (item.context_state) {
|
||||||
const historicStateObj =
|
const historicStateObj =
|
||||||
@ -337,7 +348,11 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
return html`${this.hass.localize(
|
return html`${this.hass.localize(
|
||||||
"ui.components.logbook.triggered_by_state_of"
|
"ui.components.logbook.triggered_by_state_of"
|
||||||
)}
|
)}
|
||||||
${this._renderEntity(item.context_entity_id, item.context_entity_id_name)}
|
${this._renderEntity(
|
||||||
|
item.context_entity_id,
|
||||||
|
item.context_entity_id_name,
|
||||||
|
noLink
|
||||||
|
)}
|
||||||
${historicStateObj
|
${historicStateObj
|
||||||
? localizeStateMessage(
|
? localizeStateMessage(
|
||||||
this.hass,
|
this.hass,
|
||||||
@ -379,11 +394,17 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
? "ui.components.logbook.triggered_by_automation"
|
? "ui.components.logbook.triggered_by_automation"
|
||||||
: "ui.components.logbook.triggered_by_script"
|
: "ui.components.logbook.triggered_by_script"
|
||||||
)}
|
)}
|
||||||
${this._renderEntity(item.context_entity_id, item.context_entity_id_name)}
|
${this._renderEntity(
|
||||||
|
item.context_entity_id,
|
||||||
|
item.context_entity_id_name,
|
||||||
|
noLink
|
||||||
|
)}
|
||||||
${item.context_message
|
${item.context_message
|
||||||
? this._formatMessageWithPossibleEntity(
|
? this._formatMessageWithPossibleEntity(
|
||||||
contextTriggerSource,
|
contextTriggerSource,
|
||||||
seenEntityIds
|
seenEntityIds,
|
||||||
|
undefined,
|
||||||
|
noLink
|
||||||
)
|
)
|
||||||
: ""}`;
|
: ""}`;
|
||||||
}
|
}
|
||||||
@ -394,14 +415,16 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
${this._formatMessageWithPossibleEntity(
|
${this._formatMessageWithPossibleEntity(
|
||||||
item.context_message,
|
item.context_message,
|
||||||
seenEntityIds,
|
seenEntityIds,
|
||||||
item.context_entity_id
|
item.context_entity_id,
|
||||||
|
noLink
|
||||||
)}
|
)}
|
||||||
${this._renderUnseenContextSourceEntity(item, seenEntityIds)}`;
|
${this._renderUnseenContextSourceEntity(item, seenEntityIds, noLink)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderEntity(
|
private _renderEntity(
|
||||||
entityId: string | undefined,
|
entityId: string | undefined,
|
||||||
entityName: string | undefined
|
entityName: string | undefined,
|
||||||
|
noLink?: boolean
|
||||||
) {
|
) {
|
||||||
const hasState = entityId && entityId in this.hass.states;
|
const hasState = entityId && entityId in this.hass.states;
|
||||||
const displayName =
|
const displayName =
|
||||||
@ -412,19 +435,22 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
if (!hasState) {
|
if (!hasState) {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
return html`<button
|
return noLink
|
||||||
class="link"
|
? displayName
|
||||||
@click=${this._entityClicked}
|
: html`<button
|
||||||
.entityId=${entityId}
|
class="link"
|
||||||
>
|
@click=${this._entityClicked}
|
||||||
${displayName}
|
.entityId=${entityId}
|
||||||
</button>`;
|
>
|
||||||
|
${displayName}
|
||||||
|
</button>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _formatMessageWithPossibleEntity(
|
private _formatMessageWithPossibleEntity(
|
||||||
message: string,
|
message: string,
|
||||||
seenEntities: string[],
|
seenEntities: string[],
|
||||||
possibleEntity?: string
|
possibleEntity?: string,
|
||||||
|
noLink?: boolean
|
||||||
) {
|
) {
|
||||||
//
|
//
|
||||||
// As we are looking at a log(book), we are doing entity_id
|
// As we are looking at a log(book), we are doing entity_id
|
||||||
@ -449,7 +475,8 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
return html`${messageParts.join(" ")}
|
return html`${messageParts.join(" ")}
|
||||||
${this._renderEntity(
|
${this._renderEntity(
|
||||||
entityId,
|
entityId,
|
||||||
this.hass.states[entityId].attributes.friendly_name
|
this.hass.states[entityId].attributes.friendly_name,
|
||||||
|
noLink
|
||||||
)}
|
)}
|
||||||
${messageEnd.join(" ")}`;
|
${messageEnd.join(" ")}`;
|
||||||
}
|
}
|
||||||
@ -475,7 +502,7 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
message.length - possibleEntityName.length
|
message.length - possibleEntityName.length
|
||||||
);
|
);
|
||||||
return html`${message}
|
return html`${message}
|
||||||
${this._renderEntity(possibleEntity, possibleEntityName)}`;
|
${this._renderEntity(possibleEntity, possibleEntityName, noLink)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return message;
|
return message;
|
||||||
@ -494,8 +521,12 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _close(): void {
|
_handleClick(ev) {
|
||||||
setTimeout(() => fireEvent(this, "closed"), 500);
|
if (!ev.currentTarget.traceLink) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
navigate(ev.currentTarget.traceLink);
|
||||||
|
fireEvent(this, "closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
@ -520,10 +551,20 @@ class HaLogbookRenderer extends LitElement {
|
|||||||
padding: 8px 16px;
|
padding: 8px 16px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
border-top: 1px solid var(--divider-color);
|
border-top: 1px solid var(--divider-color);
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.entry.no-entity,
|
ha-icon-next {
|
||||||
.no-name .entry {
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.clickable {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
:not(.clickable) .entry.no-entity,
|
||||||
|
:not(.clickable) .no-name .entry {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,16 +377,32 @@ export class HaLogbook extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime);
|
const nonExpiredRecords = this._nonExpiredRecords(purgeBeforePythonTime);
|
||||||
this._logbookEntries = !nonExpiredRecords.length
|
|
||||||
? // All existing entries expired
|
// Entries are sorted in descending order with newest first.
|
||||||
newEntries
|
if (!nonExpiredRecords.length) {
|
||||||
: newEntries[0].when >= nonExpiredRecords[0].when
|
// We have no records left, so we can just replace the list
|
||||||
? // The new records are newer than the old records
|
this._logbookEntries = newEntries;
|
||||||
// append the old records to the end of the new records
|
} else if (
|
||||||
newEntries.concat(nonExpiredRecords)
|
newEntries[newEntries.length - 1].when > // oldest new entry
|
||||||
: // The new records are older than the old records
|
nonExpiredRecords[0].when // newest old entry
|
||||||
// append the new records to the end of the old records
|
) {
|
||||||
nonExpiredRecords.concat(newEntries);
|
// The new records are newer than the old records
|
||||||
|
// append the old records to the end of the new records
|
||||||
|
this._logbookEntries = newEntries.concat(nonExpiredRecords);
|
||||||
|
} else if (
|
||||||
|
nonExpiredRecords[nonExpiredRecords.length - 1].when > // oldest old entry
|
||||||
|
newEntries[0].when // newest new entry
|
||||||
|
) {
|
||||||
|
// The new records are older than the old records
|
||||||
|
// append the new records to the end of the old records
|
||||||
|
this._logbookEntries = nonExpiredRecords.concat(newEntries);
|
||||||
|
} else {
|
||||||
|
// The new records are in the middle of the old records
|
||||||
|
// so we need to re-sort them
|
||||||
|
this._logbookEntries = nonExpiredRecords
|
||||||
|
.concat(newEntries)
|
||||||
|
.sort((a, b) => b.when - a.when);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private _updateTraceContexts = throttle(async () => {
|
private _updateTraceContexts = throttle(async () => {
|
||||||
|
@ -301,6 +301,7 @@
|
|||||||
"refresh": "Refresh",
|
"refresh": "Refresh",
|
||||||
"cancel": "Cancel",
|
"cancel": "Cancel",
|
||||||
"delete": "Delete",
|
"delete": "Delete",
|
||||||
|
"duplicate": "Duplicate",
|
||||||
"remove": "Remove",
|
"remove": "Remove",
|
||||||
"enable": "Enable",
|
"enable": "Enable",
|
||||||
"disable": "Disable",
|
"disable": "Disable",
|
||||||
@ -1790,9 +1791,9 @@
|
|||||||
"edit_automation": "Edit automation",
|
"edit_automation": "Edit automation",
|
||||||
"dev_automation": "Debug automation",
|
"dev_automation": "Debug automation",
|
||||||
"show_info_automation": "Show info about automation",
|
"show_info_automation": "Show info about automation",
|
||||||
"delete": "Delete",
|
"delete": "[%key:ui::common::delete%]",
|
||||||
"delete_confirm": "Are you sure you want to delete this automation?",
|
"delete_confirm": "Are you sure you want to delete this automation?",
|
||||||
"duplicate": "Duplicate",
|
"duplicate": "[%key:ui::common::duplicate%]",
|
||||||
"disabled": "Disabled",
|
"disabled": "Disabled",
|
||||||
"headers": {
|
"headers": {
|
||||||
"toggle": "Enable/disable",
|
"toggle": "Enable/disable",
|
||||||
@ -1824,7 +1825,6 @@
|
|||||||
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
||||||
"show_trace": "Traces",
|
"show_trace": "Traces",
|
||||||
"show_info": "Information",
|
"show_info": "Information",
|
||||||
"introduction": "Use automations to bring your home to life.",
|
|
||||||
"default_name": "New Automation",
|
"default_name": "New Automation",
|
||||||
"missing_name": "Cannot save automation without a name",
|
"missing_name": "Cannot save automation without a name",
|
||||||
"load_error_not_editable": "Only automations in automations.yaml are editable.",
|
"load_error_not_editable": "Only automations in automations.yaml are editable.",
|
||||||
@ -1836,6 +1836,12 @@
|
|||||||
"automation_settings": "Automation settings",
|
"automation_settings": "Automation settings",
|
||||||
"move_up": "Move up",
|
"move_up": "Move up",
|
||||||
"move_down": "Move down",
|
"move_down": "Move down",
|
||||||
|
"re_order": "Re-order",
|
||||||
|
"re_order_mode": {
|
||||||
|
"title": "Re-order mode",
|
||||||
|
"description": "You are in re-order mode, you can re-order your triggers, conditions and actions.",
|
||||||
|
"exit": "Exit"
|
||||||
|
},
|
||||||
"description": {
|
"description": {
|
||||||
"label": "Description",
|
"label": "Description",
|
||||||
"placeholder": "Optional description",
|
"placeholder": "Optional description",
|
||||||
@ -1847,6 +1853,7 @@
|
|||||||
"no_blueprints": "You don't have any blueprints",
|
"no_blueprints": "You don't have any blueprints",
|
||||||
"no_inputs": "This blueprint doesn't have any inputs."
|
"no_inputs": "This blueprint doesn't have any inputs."
|
||||||
},
|
},
|
||||||
|
"change_mode": "Change mode",
|
||||||
"modes": {
|
"modes": {
|
||||||
"label": "Mode",
|
"label": "Mode",
|
||||||
"learn_more": "Learn about modes",
|
"learn_more": "Learn about modes",
|
||||||
@ -1869,11 +1876,11 @@
|
|||||||
"add": "Add trigger",
|
"add": "Add trigger",
|
||||||
"id": "Trigger ID",
|
"id": "Trigger ID",
|
||||||
"edit_id": "Edit ID",
|
"edit_id": "Edit ID",
|
||||||
"duplicate": "Duplicate",
|
"duplicate": "[%key:ui::common::duplicate%]",
|
||||||
"rename": "Rename",
|
"rename": "Rename",
|
||||||
"change_alias": "Rename trigger",
|
"change_alias": "Rename trigger",
|
||||||
"alias": "Trigger name",
|
"alias": "Trigger name",
|
||||||
"delete": "[%key:ui::panel::mailbox::delete_button%]",
|
"delete": "[%key:ui::common::delete%]",
|
||||||
"delete_confirm": "Are you sure you want to delete this?",
|
"delete_confirm": "Are you sure you want to delete this?",
|
||||||
"unsupported_platform": "No visual editor support for platform: {platform}",
|
"unsupported_platform": "No visual editor support for platform: {platform}",
|
||||||
"type_select": "Trigger type",
|
"type_select": "Trigger type",
|
||||||
@ -1989,11 +1996,11 @@
|
|||||||
"testing_pass": "Condition passes",
|
"testing_pass": "Condition passes",
|
||||||
"invalid_condition": "Invalid condition configuration",
|
"invalid_condition": "Invalid condition configuration",
|
||||||
"test_failed": "Error occurred while testing condition",
|
"test_failed": "Error occurred while testing condition",
|
||||||
"duplicate": "[%key:ui::panel::config::automation::editor::triggers::duplicate%]",
|
"duplicate": "[%key:ui::common::duplicate%]",
|
||||||
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
||||||
"change_alias": "Rename condition",
|
"change_alias": "Rename condition",
|
||||||
"alias": "Condition name",
|
"alias": "Condition name",
|
||||||
"delete": "[%key:ui::panel::mailbox::delete_button%]",
|
"delete": "[%key:ui::common::delete%]",
|
||||||
"delete_confirm": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm%]",
|
"delete_confirm": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm%]",
|
||||||
"unsupported_condition": "No visual editor support for condition: {condition}",
|
"unsupported_condition": "No visual editor support for condition: {condition}",
|
||||||
"type_select": "Condition type",
|
"type_select": "Condition type",
|
||||||
@ -2080,14 +2087,14 @@
|
|||||||
"run": "Run",
|
"run": "Run",
|
||||||
"run_action_error": "Error running action",
|
"run_action_error": "Error running action",
|
||||||
"run_action_success": "Action run successfully",
|
"run_action_success": "Action run successfully",
|
||||||
"duplicate": "[%key:ui::panel::config::automation::editor::triggers::duplicate%]",
|
"duplicate": "[%key:ui::common::duplicate%]",
|
||||||
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
"rename": "[%key:ui::panel::config::automation::editor::triggers::rename%]",
|
||||||
"change_alias": "Rename action",
|
"change_alias": "Rename action",
|
||||||
"alias": "Action name",
|
"alias": "Action name",
|
||||||
"enable": "Enable",
|
"enable": "Enable",
|
||||||
"disable": "Disable",
|
"disable": "Disable",
|
||||||
"disabled": "Disabled",
|
"disabled": "Disabled",
|
||||||
"delete": "[%key:ui::panel::mailbox::delete_button%]",
|
"delete": "[%key:ui::common::delete%]",
|
||||||
"delete_confirm": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm%]",
|
"delete_confirm": "[%key:ui::panel::config::automation::editor::triggers::delete_confirm%]",
|
||||||
"unsupported_action": "No visual editor support for action: {action}",
|
"unsupported_action": "No visual editor support for action: {action}",
|
||||||
"type_select": "Action type",
|
"type_select": "Action type",
|
||||||
@ -2260,7 +2267,7 @@
|
|||||||
"header": "Script Editor",
|
"header": "Script Editor",
|
||||||
"introduction": "The script editor allows you to create and edit scripts. Please follow the link below to read the instructions to make sure that you have configured Home Assistant correctly.",
|
"introduction": "The script editor allows you to create and edit scripts. Please follow the link below to read the instructions to make sure that you have configured Home Assistant correctly.",
|
||||||
"learn_more": "Learn more about scripts",
|
"learn_more": "Learn more about scripts",
|
||||||
"no_scripts": "We couldn’t find any scripts",
|
"no_scripts": "We couldn't find any scripts",
|
||||||
"add_script": "Add script",
|
"add_script": "Add script",
|
||||||
"show_info": "Show info about script",
|
"show_info": "Show info about script",
|
||||||
"run_script": "Run script",
|
"run_script": "Run script",
|
||||||
@ -2270,8 +2277,8 @@
|
|||||||
"name": "Name",
|
"name": "Name",
|
||||||
"state": "State"
|
"state": "State"
|
||||||
},
|
},
|
||||||
"duplicate_script": "Duplicate script",
|
"delete": "[%key:ui::common::delete%]",
|
||||||
"duplicate": "[%key:ui::panel::config::automation::picker::duplicate%]"
|
"duplicate": "[%key:ui::common::duplicate%]"
|
||||||
},
|
},
|
||||||
"editor": {
|
"editor": {
|
||||||
"alias": "Name",
|
"alias": "Name",
|
||||||
@ -2298,7 +2305,6 @@
|
|||||||
"load_error_not_editable": "Only scripts inside scripts.yaml are editable.",
|
"load_error_not_editable": "Only scripts inside scripts.yaml are editable.",
|
||||||
"load_error_unknown": "Error loading script ({err_no}).",
|
"load_error_unknown": "Error loading script ({err_no}).",
|
||||||
"delete_confirm": "Are you sure you want to delete this script?",
|
"delete_confirm": "Are you sure you want to delete this script?",
|
||||||
"delete_script": "Delete script",
|
|
||||||
"save_script": "Save script",
|
"save_script": "Save script",
|
||||||
"sequence": "Sequence",
|
"sequence": "Sequence",
|
||||||
"sequence_sentence": "The sequence of actions of this script.",
|
"sequence_sentence": "The sequence of actions of this script.",
|
||||||
@ -2314,7 +2320,7 @@
|
|||||||
"introduction": "The scene editor allows you to create and edit scenes. Please follow the link below to read the instructions to make sure that you have configured Home Assistant correctly.",
|
"introduction": "The scene editor allows you to create and edit scenes. Please follow the link below to read the instructions to make sure that you have configured Home Assistant correctly.",
|
||||||
"learn_more": "Learn more about scenes",
|
"learn_more": "Learn more about scenes",
|
||||||
"pick_scene": "Pick scene to edit",
|
"pick_scene": "Pick scene to edit",
|
||||||
"no_scenes": "We couldn’t find any scenes",
|
"no_scenes": "We couldn't find any scenes",
|
||||||
"add_scene": "Add scene",
|
"add_scene": "Add scene",
|
||||||
"only_editable": "Only scenes defined in scenes.yaml are editable.",
|
"only_editable": "Only scenes defined in scenes.yaml are editable.",
|
||||||
"edit_scene": "Edit scene",
|
"edit_scene": "Edit scene",
|
||||||
@ -2322,7 +2328,7 @@
|
|||||||
"delete_scene": "Delete scene",
|
"delete_scene": "Delete scene",
|
||||||
"delete_confirm": "Are you sure you want to delete this scene?",
|
"delete_confirm": "Are you sure you want to delete this scene?",
|
||||||
"duplicate_scene": "Duplicate scene",
|
"duplicate_scene": "Duplicate scene",
|
||||||
"duplicate": "Duplicate",
|
"duplicate": "[%key:ui::common::duplicate%]",
|
||||||
"headers": {
|
"headers": {
|
||||||
"activate": "Activate",
|
"activate": "Activate",
|
||||||
"state": "State",
|
"state": "State",
|
||||||
@ -2332,7 +2338,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"editor": {
|
"editor": {
|
||||||
"introduction": "Use scenes to bring your home to life.",
|
|
||||||
"default_name": "New Scene",
|
"default_name": "New Scene",
|
||||||
"load_error_not_editable": "Only scenes in scenes.yaml are editable.",
|
"load_error_not_editable": "Only scenes in scenes.yaml are editable.",
|
||||||
"load_error_unknown": "Error loading scene ({err_no}).",
|
"load_error_unknown": "Error loading scene ({err_no}).",
|
||||||
@ -3855,7 +3860,7 @@
|
|||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
"name": "Entity",
|
"name": "Entity",
|
||||||
"description": "The Entity card gives you a quick overview of your entity’s state."
|
"description": "The Entity card gives you a quick overview of your entity's state."
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
"name": "Button",
|
"name": "Button",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user