From 9bc67bd0cf96d13b34024555e5714852427526b1 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 15 May 2017 22:05:12 -0700 Subject: [PATCH] Allow creating new automations. --- panels/automation/ha-automation-editor.html | 34 +++++++++++++++++-- panels/automation/ha-automation-picker.html | 28 ++++++++++++++++ panels/automation/ha-panel-automation.html | 37 ++++++++++++++++++--- 3 files changed, 91 insertions(+), 8 deletions(-) diff --git a/panels/automation/ha-automation-editor.html b/panels/automation/ha-automation-editor.html index 9fc1c74132..68d3e4b549 100644 --- a/panels/automation/ha-automation-editor.html +++ b/panels/automation/ha-automation-editor.html @@ -141,6 +141,11 @@ Polymer({ observer: 'automationChanged', }, + creatingNew: { + type: Boolean, + observer: 'creatingNewChanged', + }, + name: { type: String, computed: 'computeName(automation)' @@ -152,7 +157,7 @@ Polymer({ }, }, - attached: function () { + created: function () { this.configChanged = this.configChanged.bind(this); }, @@ -194,6 +199,23 @@ Polymer({ }.bind(this)); }, + creatingNewChanged: function (newVal) { + if (!newVal) { + return; + } + this.dirty = false; + this.config = { + alias: 'New Automation', + trigger: [ + { platform: 'state' }, + ], + action: [ + { service: '' }, + ], + }; + this._updateComponent(); + }, + isWideChanged: function () { if (this.config === null) return; this._updateComponent(); @@ -218,10 +240,16 @@ Polymer({ }, saveAutomation: function () { + var id = this.creatingNew ? '' + Date.now() : this.automation.attributes.id; this.hass.callApi( - 'post', 'config/automation/config/' + this.automation.attributes.id, - this.config).then(function () { + 'post', 'config/automation/config/' + id, this.config).then(function () { this.dirty = false; + + if (this.creatingNew) { + this.fire('hass-automation-picked', { + id: id, + }); + } }.bind(this), function (errors) { this.errors = errors.body.message; throw errors; diff --git a/panels/automation/ha-automation-picker.html b/panels/automation/ha-automation-picker.html index 961e89bd61..ef52eed2fd 100644 --- a/panels/automation/ha-automation-picker.html +++ b/panels/automation/ha-automation-picker.html @@ -5,6 +5,7 @@ + + + @@ -91,6 +111,10 @@ Polymer({ automations: { type: Array, }, + + isWide: { + type: Boolean, + }, }, automationTapped: function (ev) { @@ -99,6 +123,10 @@ Polymer({ }); }, + addAutomation: function () { + this.fire('hass-create-automation'); + }, + computeName: function (automation) { return window.hassUtil.computeStateName(automation); }, diff --git a/panels/automation/ha-panel-automation.html b/panels/automation/ha-panel-automation.html index 0cd4555cc2..e5a097e6f0 100644 --- a/panels/automation/ha-panel-automation.html +++ b/panels/automation/ha-panel-automation.html @@ -18,17 +18,19 @@ -