mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Allow automation/script delete (#3194)
This commit is contained in:
parent
087c3b9c0e
commit
be0bef3f1b
@ -2,6 +2,7 @@ import {
|
||||
HassEntityBase,
|
||||
HassEntityAttributeBase,
|
||||
} from "home-assistant-js-websocket";
|
||||
import { HomeAssistant } from "../types";
|
||||
|
||||
export interface AutomationEntity extends HassEntityBase {
|
||||
attributes: HassEntityAttributeBase & {
|
||||
@ -16,3 +17,6 @@ export interface AutomationConfig {
|
||||
condition?: any[];
|
||||
action: any[];
|
||||
}
|
||||
|
||||
export const deleteAutomation = (hass: HomeAssistant, id: string) =>
|
||||
hass.callApi("DELETE", `config/automation/config/${id}`);
|
||||
|
@ -12,3 +12,6 @@ export const triggerScript = (
|
||||
entityId: string,
|
||||
variables?: {}
|
||||
) => hass.callService("script", computeObjectId(entityId), variables);
|
||||
|
||||
export const deleteScript = (hass: HomeAssistant, objectId: string) =>
|
||||
hass.callApi("DELETE", `config/script/config/${objectId}`);
|
||||
|
@ -24,7 +24,11 @@ import computeStateName from "../../../common/entity/compute_state_name";
|
||||
|
||||
import { haStyle } from "../../../resources/styles";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { AutomationEntity, AutomationConfig } from "../../../data/automation";
|
||||
import {
|
||||
AutomationEntity,
|
||||
AutomationConfig,
|
||||
deleteAutomation,
|
||||
} from "../../../data/automation";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||
|
||||
@ -33,8 +37,8 @@ function AutomationEditor(mountEl, props, mergeEl) {
|
||||
}
|
||||
|
||||
class HaAutomationEditor extends LitElement {
|
||||
public hass?: HomeAssistant;
|
||||
public automation?: AutomationEntity;
|
||||
public hass!: HomeAssistant;
|
||||
public automation!: AutomationEntity;
|
||||
public isWide?: boolean;
|
||||
public creatingNew?: boolean;
|
||||
private _config?: AutomationConfig;
|
||||
@ -85,6 +89,14 @@ class HaAutomationEditor extends LitElement {
|
||||
"ui.panel.config.automation.editor.default_name"
|
||||
)}
|
||||
</div>
|
||||
${this.creatingNew
|
||||
? ""
|
||||
: html`
|
||||
<paper-icon-button
|
||||
icon="hass:delete"
|
||||
@click=${this._delete}
|
||||
></paper-icon-button>
|
||||
`}
|
||||
</app-toolbar>
|
||||
</app-header>
|
||||
|
||||
@ -184,7 +196,6 @@ class HaAutomationEditor extends LitElement {
|
||||
this._config = config;
|
||||
this._errors = undefined;
|
||||
this._dirty = true;
|
||||
// this._updateComponent();
|
||||
}
|
||||
|
||||
private _backTapped(): void {
|
||||
@ -199,10 +210,18 @@ class HaAutomationEditor extends LitElement {
|
||||
history.back();
|
||||
}
|
||||
|
||||
private async _delete() {
|
||||
if (!confirm("Are you sure you want to delete this automation?")) {
|
||||
return;
|
||||
}
|
||||
await deleteAutomation(this.hass, this.automation.attributes.id!);
|
||||
history.back();
|
||||
}
|
||||
|
||||
private _saveAutomation(): void {
|
||||
const id = this.creatingNew
|
||||
? "" + Date.now()
|
||||
: this.automation!.attributes.id;
|
||||
: this.automation.attributes.id;
|
||||
this.hass!.callApi(
|
||||
"POST",
|
||||
"config/automation/config/" + id,
|
||||
|
@ -26,6 +26,7 @@ import { HomeAssistant } from "../../../types";
|
||||
import { AutomationEntity } from "../../../data/automation";
|
||||
import format_date_time from "../../../common/datetime/format_date_time";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { repeat } from "lit-html/directives/repeat";
|
||||
|
||||
@customElement("ha-automation-picker")
|
||||
class HaAutomationPicker extends LitElement {
|
||||
@ -73,7 +74,9 @@ class HaAutomationPicker extends LitElement {
|
||||
</p>
|
||||
</div>
|
||||
`
|
||||
: this.automations.map(
|
||||
: repeat(
|
||||
this.automations,
|
||||
(automation) => automation.entity_id,
|
||||
(automation) => html`
|
||||
|
||||
<div class='automation'>
|
||||
|
@ -18,6 +18,7 @@ import NavigateMixin from "../../../mixins/navigate-mixin";
|
||||
import LocalizeMixin from "../../../mixins/localize-mixin";
|
||||
|
||||
import { computeRTL } from "../../../common/util/compute_rtl";
|
||||
import { deleteScript } from "../../../data/script";
|
||||
|
||||
function ScriptEditor(mountEl, props, mergeEl) {
|
||||
return render(h(Script, props), mountEl, mergeEl);
|
||||
@ -99,7 +100,13 @@ class HaScriptEditor extends LocalizeMixin(NavigateMixin(PolymerElement)) {
|
||||
<ha-paper-icon-button-arrow-prev
|
||||
on-click="backTapped"
|
||||
></ha-paper-icon-button-arrow-prev>
|
||||
<div main-title="">Script [[computeName(script)]]</div>
|
||||
<div main-title>Script [[computeName(script)]]</div>
|
||||
<template is="dom-if" if="[[!creatingNew]]">
|
||||
<paper-icon-button
|
||||
icon="hass:delete"
|
||||
on-click="_delete"
|
||||
></paper-icon-button>
|
||||
</template>
|
||||
</app-toolbar>
|
||||
</app-header>
|
||||
<div class="content">
|
||||
@ -273,6 +280,14 @@ class HaScriptEditor extends LocalizeMixin(NavigateMixin(PolymerElement)) {
|
||||
});
|
||||
}
|
||||
|
||||
async _delete() {
|
||||
if (!confirm("Are you sure you want to delete this script?")) {
|
||||
return;
|
||||
}
|
||||
await deleteScript(this.hass, computeObjectId(this.script.entity_id));
|
||||
history.back();
|
||||
}
|
||||
|
||||
saveScript() {
|
||||
var id = this.creatingNew
|
||||
? "" + Date.now()
|
||||
|
@ -25,6 +25,7 @@ import { haStyle } from "../../../resources/styles";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { triggerScript } from "../../../data/script";
|
||||
import { showToast } from "../../../util/toast";
|
||||
import { repeat } from "lit-html/directives/repeat";
|
||||
|
||||
@customElement("ha-script-picker")
|
||||
class HaScriptPicker extends LitElement {
|
||||
@ -56,7 +57,9 @@ class HaScriptPicker extends LitElement {
|
||||
<p>We couldn't find any scripts.</p>
|
||||
</div>
|
||||
`
|
||||
: this.scripts.map(
|
||||
: repeat(
|
||||
this.scripts,
|
||||
(script) => script.entity_id,
|
||||
(script) => html`
|
||||
<div class="script">
|
||||
<paper-icon-button
|
||||
|
Loading…
x
Reference in New Issue
Block a user