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