Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/data/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export type Condition =
| DeviceCondition
| LogicalCondition;

export const triggerAutomation = (hass: HomeAssistant, entityId: string) => {
hass.callService("automation", "trigger", {
entity_id: entityId,
});
};

export const deleteAutomation = (hass: HomeAssistant, id: string) =>
hass.callApi("DELETE", `config/automation/config/${id}`);

Expand Down
5 changes: 2 additions & 3 deletions src/dialogs/more-info/controls/more-info-automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "@material/mwc-button";
import "../../../components/ha-relative-time";

import { HomeAssistant } from "../../../types";
import { triggerAutomation } from "../../../data/automation";

@customElement("more-info-automation")
class MoreInfoAutomation extends LitElement {
Expand Down Expand Up @@ -42,9 +43,7 @@ class MoreInfoAutomation extends LitElement {
}

private handleAction() {
this.hass.callService("automation", "trigger", {
entity_id: this.stateObj!.entity_id,
});
triggerAutomation(this.hass, this.stateObj!.entity_id);
}

static get styles(): CSSResult {
Expand Down
30 changes: 30 additions & 0 deletions src/panels/config/automation/ha-automation-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
deleteAutomation,
getAutomationEditorInitData,
Trigger,
triggerAutomation,
} from "../../../data/automation";
import { Action } from "../../../data/script";
import {
Expand Down Expand Up @@ -111,6 +112,28 @@ export class HaAutomationEditor extends LitElement {
@value-changed=${this._valueChanged}
></ha-textarea>
</div>
${this.creatingNew
? ""
: html`
<div
class="card-actions layout horizontal justified center"
>
<div class="layout horizontal center">
<ha-entity-toggle
.hass=${this.hass}
.stateObj=${this.automation}
></ha-entity-toggle>
${this.hass.localize(
"ui.panel.config.automation.editor.enable_disable"
)}
</div>
<mwc-button @click=${this._excuteAutomation}>
${this.hass.localize(
"ui.card.automation.trigger"
)}
</mwc-button>
</div>
`}
</ha-card>
</ha-config-section>

Expand Down Expand Up @@ -317,6 +340,10 @@ export class HaAutomationEditor extends LitElement {
this._dirty = true;
}

private _excuteAutomation() {
triggerAutomation(this.hass, this.automation.entity_id);
}

private _backTapped(): void {
if (this._dirty) {
showConfirmationDialog(this, {
Expand Down Expand Up @@ -389,6 +416,9 @@ export class HaAutomationEditor extends LitElement {
span[slot="introduction"] a {
color: var(--primary-color);
}
ha-entity-toggle {
margin-right: 8px;
}
ha-fab {
position: fixed;
bottom: 16px;
Expand Down
41 changes: 41 additions & 0 deletions src/resources/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,47 @@ export const haStyle = css`
.card-actions .warning {
--mdc-theme-primary: var(--google-red-500);
}

.layout.horizontal,
Comment thread
bramkragten marked this conversation as resolved.
.layout.vertical {
display: flex;
}
.layout.inline {
display: inline-flex;
}
.layout.horizontal {
flex-direction: row;
}
.layout.vertical {
flex-direction: column;
}
.layout.wrap {
flex-wrap: wrap;
}
.layout.no-wrap {
flex-wrap: nowrap;
}
.layout.center,
.layout.center-center {
align-items: center;
}
.layout.center-justified,
.layout.center-center {
justify-content: center;
}
.flex {
flex: 1;
flex-basis: 0.000000001px;
}
.flex-auto {
flex: 1 1 auto;
}
.flex-none {
flex: none;
}
.layout.justified {
justify-content: space-between;
}
`;

export const haStyleDialog = css`
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@
"delete_confirm": "Are you sure you want to delete this automation?"
},
"editor": {
"enable_disable": "Enable/Disable automation",
"introduction": "Use automations to bring your home alive.",
"default_name": "New Automation",
"load_error_not_editable": "Only automations in automations.yaml are editable.",
Expand Down