Make clear that automation run button skips conditions + remove word "execute" from UI (#8259)

* Do not skip conditions when triggering an automation

* Remove usage of word "execute"

* More concise function names
This commit is contained in:
Philip Allgaier 2021-02-25 14:17:31 +01:00 committed by GitHub
parent 81f96de2bd
commit 32ba8f4731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 52 additions and 44 deletions

View File

@ -205,9 +205,13 @@ export type Condition =
| DeviceCondition
| LogicalCondition;
export const triggerAutomation = (hass: HomeAssistant, entityId: string) => {
export const triggerAutomationActions = (
hass: HomeAssistant,
entityId: string
) => {
hass.callService("automation", "trigger", {
entity_id: entityId,
skip_condition: true,
});
};

View File

@ -117,7 +117,7 @@ export const triggerScript = (
variables?: Record<string, unknown>
) => hass.callService("script", computeObjectId(entityId), variables);
export const canExcecute = (state: ScriptEntity) => {
export const canRun = (state: ScriptEntity) => {
if (state.state === "off") {
return true;
}

View File

@ -10,7 +10,7 @@ import {
TemplateResult,
} from "lit-element";
import "../../../components/ha-relative-time";
import { triggerAutomation } from "../../../data/automation";
import { triggerAutomationActions } from "../../../data/automation";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { HomeAssistant } from "../../../types";
@ -36,7 +36,7 @@ class MoreInfoAutomation extends LitElement {
<div class="actions">
<mwc-button
@click=${this.handleAction}
@click=${this._runActions}
.disabled=${UNAVAILABLE_STATES.includes(this.stateObj!.state)}
>
${this.hass.localize("ui.card.automation.trigger")}
@ -45,8 +45,8 @@ class MoreInfoAutomation extends LitElement {
`;
}
private handleAction() {
triggerAutomation(this.hass, this.stateObj!.entity_id);
private _runActions() {
triggerAutomationActions(this.hass, this.stateObj!.entity_id);
}
static get styles(): CSSResult {

View File

@ -21,7 +21,7 @@ import "../../../components/ha-selector/ha-selector";
import "../../../components/ha-settings-row";
import {
BlueprintAutomationConfig,
triggerAutomation,
triggerAutomationActions,
} from "../../../data/automation";
import {
BlueprintOrError,
@ -105,7 +105,7 @@ export class HaBlueprintAutomationEditor extends LitElement {
)}
</div>
<mwc-button
@click=${this._excuteAutomation}
@click=${this._runActions}
.stateObj=${this.stateObj}
>
${this.hass.localize("ui.card.automation.trigger")}
@ -197,8 +197,8 @@ export class HaBlueprintAutomationEditor extends LitElement {
this._blueprints = await fetchBlueprints(this.hass, "automation");
}
private _excuteAutomation(ev: Event) {
triggerAutomation(this.hass, (ev.target as any).stateObj.entity_id);
private _runActions(ev: Event) {
triggerAutomationActions(this.hass, (ev.target as any).stateObj.entity_id);
}
private _blueprintChanged(ev) {

View File

@ -38,7 +38,7 @@ import {
deleteAutomation,
getAutomationEditorInitData,
showAutomationEditor,
triggerAutomation,
triggerAutomationActions,
} from "../../../data/automation";
import {
showAlertDialog,
@ -256,7 +256,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
)}
</div>
<mwc-button
@click=${this._excuteAutomation}
@click=${this._runActions}
.stateObj=${stateObj}
>
${this.hass.localize(
@ -381,8 +381,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
this._errors = undefined;
}
private _excuteAutomation(ev: Event) {
triggerAutomation(this.hass, (ev.target as any).stateObj.entity_id);
private _runActions(ev: Event) {
triggerAutomationActions(this.hass, (ev.target as any).stateObj.entity_id);
}
private _preprocessYaml() {

View File

@ -20,7 +20,10 @@ import { DataTableColumnContainer } from "../../../components/data-table/ha-data
import "../../../components/entity/ha-entity-toggle";
import "../../../components/ha-fab";
import "../../../components/ha-svg-icon";
import { AutomationEntity, triggerAutomation } from "../../../data/automation";
import {
AutomationEntity,
triggerAutomationActions,
} from "../../../data/automation";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
import "../../../layouts/hass-tabs-subpage-data-table";
@ -88,12 +91,12 @@ class HaAutomationPicker extends LitElement {
},
};
if (!narrow) {
columns.execute = {
columns.trigger = {
title: "",
template: (_info, automation: any) => html`
<mwc-button
.automation=${automation}
@click=${(ev) => this._execute(ev)}
@click=${(ev) => this._runActions(ev)}
.disabled=${UNAVAILABLE_STATES.includes(automation.state)}
>
${this.hass.localize("ui.card.automation.trigger")}
@ -210,9 +213,9 @@ class HaAutomationPicker extends LitElement {
});
}
private _execute(ev) {
private _runActions(ev) {
const entityId = ev.currentTarget.automation.entity_id;
triggerAutomation(this.hass, entityId);
triggerAutomationActions(this.hass, entityId);
}
private _createNew() {

View File

@ -18,7 +18,7 @@ import {
Condition,
ManualAutomationConfig,
Trigger,
triggerAutomation,
triggerAutomationActions,
} from "../../../data/automation";
import { Action, MODES, MODES_MAX } from "../../../data/script";
import { haStyle } from "../../../resources/styles";
@ -140,7 +140,7 @@ export class HaManualAutomationEditor extends LitElement {
)}
</div>
<mwc-button
@click=${this._excuteAutomation}
@click=${this._runActions}
.stateObj=${this.stateObj}
>
${this.hass.localize("ui.card.automation.trigger")}
@ -240,8 +240,8 @@ export class HaManualAutomationEditor extends LitElement {
</ha-config-section>`;
}
private _excuteAutomation(ev: Event) {
triggerAutomation(this.hass, (ev.target as any).stateObj.entity_id);
private _runActions(ev: Event) {
triggerAutomationActions(this.hass, (ev.target as any).stateObj.entity_id);
}
private _valueChanged(ev: CustomEvent) {

View File

@ -299,12 +299,12 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
<mwc-button
@click=${this._runScript}
title="${this.hass.localize(
"ui.panel.config.script.picker.activate_script"
"ui.panel.config.script.picker.run_script"
)}"
?disabled=${this._dirty}
>
${this.hass.localize(
"ui.card.script.execute"
"ui.panel.config.script.picker.run_script"
)}
</mwc-button>
</div>
@ -375,11 +375,13 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
<mwc-button
@click=${this._runScript}
title="${this.hass.localize(
"ui.panel.config.script.picker.activate_script"
"ui.panel.config.script.picker.run_script"
)}"
?disabled=${this._dirty}
>
${this.hass.localize("ui.card.script.execute")}
${this.hass.localize(
"ui.panel.config.script.picker.run_script"
)}
</mwc-button>
</div>
`

View File

@ -11,7 +11,7 @@ import {
TemplateResult,
} from "lit-element";
import { UNAVAILABLE_STATES } from "../../../data/entity";
import { canExcecute, ScriptEntity } from "../../../data/script";
import { canRun, ScriptEntity } from "../../../data/script";
import { HomeAssistant } from "../../../types";
import { hasConfigOrEntityChanged } from "../common/has-changed";
import "../components/hui-generic-entity-row";
@ -66,12 +66,12 @@ class HuiScriptEntityRow extends LitElement implements LovelaceRow {
: ""}
${stateObj.state === "off" || stateObj.attributes.max
? html`<mwc-button
@click=${this._executeScript}
@click=${this._runScript}
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state) ||
!canExcecute(stateObj)}
!canRun(stateObj)}
>
${this._config.action_name ||
this.hass!.localize("ui.card.script.execute")}
this.hass!.localize("ui.card.script.run")}
</mwc-button>`
: ""}
</hui-generic-entity-row>
@ -91,7 +91,7 @@ class HuiScriptEntityRow extends LitElement implements LovelaceRow {
this._callService("turn_off");
}
private _executeScript(ev): void {
private _runScript(ev): void {
ev.stopPropagation();
this._callService("turn_on");
}

View File

@ -10,7 +10,7 @@ import {
import "../components/entity/ha-entity-toggle";
import "../components/entity/state-info";
import { UNAVAILABLE_STATES } from "../data/entity";
import { canExcecute, ScriptEntity } from "../data/script";
import { canRun, ScriptEntity } from "../data/script";
import { haStyle } from "../resources/styles";
import { HomeAssistant } from "../types";
@ -45,11 +45,11 @@ export class StateCardScript extends LitElement {
: ""}
${stateObj.state === "off" || stateObj.attributes.max
? html`<mwc-button
@click=${this._executeScript}
@click=${this._runScript}
.disabled=${UNAVAILABLE_STATES.includes(stateObj.state) ||
!canExcecute(stateObj)}
!canRun(stateObj)}
>
${this.hass!.localize("ui.card.script.execute")}
${this.hass!.localize("ui.card.script.run")}
</mwc-button>`
: ""}
</div>
@ -61,7 +61,7 @@ export class StateCardScript extends LitElement {
this._callService("turn_off");
}
private _executeScript(ev: Event) {
private _runScript(ev: Event) {
ev.stopPropagation();
this._callService("turn_on");
}

View File

@ -120,7 +120,7 @@
},
"automation": {
"last_triggered": "Last triggered",
"trigger": "Execute"
"trigger": "Run Actions"
},
"camera": {
"not_available": "Image not available"
@ -199,7 +199,7 @@
"activate": "Activate"
},
"script": {
"execute": "Execute",
"run": "[%key:ui::card::service::run%]",
"cancel": "Cancel",
"cancel_multiple": "Cancel {number}"
},
@ -1337,7 +1337,7 @@
"conditions": {
"name": "Condition",
"header": "Conditions",
"introduction": "Conditions are optional and will prevent further execution unless all conditions are satisfied.",
"introduction": "Conditions are optional and will prevent the automation from running unless all conditions are satisfied.",
"learn_more": "Learn more about conditions",
"add": "Add condition",
"duplicate": "[%key:ui::panel::config::automation::editor::triggers::duplicate%]",
@ -1553,7 +1553,6 @@
"no_scripts": "We couldnt find any editable scripts",
"add_script": "Add script",
"show_info": "Show info about script",
"trigger_script": "Trigger script",
"run_script": "Run script",
"edit_script": "Edit script",
"headers": {
@ -1568,7 +1567,7 @@
"id": "Entity ID",
"id_already_exists_save_error": "You can't save this script because the ID is not unique, pick another ID or leave it blank to automatically generate one.",
"id_already_exists": "This ID already exists",
"introduction": "Use scripts to execute a sequence of actions.",
"introduction": "Use scripts to run a sequence of actions.",
"header": "Script: {name}",
"default_name": "New Script",
"modes": {
@ -2559,12 +2558,12 @@
"cards": {
"confirm_delete": "Are you sure you want to delete this card?",
"actions": {
"action_confirmation": "Are you sure you want to execute action \"{action}\"?",
"action_confirmation": "Are you sure you want to run action \"{action}\"?",
"no_entity_more_info": "No entity provided for more info dialog",
"no_entity_toggle": "No entity provided to toggle",
"no_navigation_path": "No navigation path specified",
"no_url": "No URL to open specified",
"no_service": "No service for execution specified"
"no_service": "No service to run specified"
},
"empty_state": {
"title": "Welcome Home",