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 @@
+
@@ -31,6 +32,18 @@
paper-item {
cursor: pointer;
}
+
+ paper-fab {
+ position: fixed;
+ bottom: 16px;
+ right: 16px;
+ z-index: 1;
+ }
+
+ paper-fab[is-wide] {
+ bottom: 24px;
+ right: 24px;
+ }
@@ -64,6 +77,13 @@
+
+
@@ -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 @@
-
+
-
+
@@ -64,7 +66,7 @@ Polymer({
automation: {
type: Object,
- computed: 'computeAutomation(automations, automationId)',
+ computed: 'computeAutomation(automations, automationId, creatingNew)',
},
wide: {
@@ -79,17 +81,31 @@ Polymer({
type: Boolean,
computed: 'computeIsWide(showMenu, wideSidebar, wide)'
},
+
+ creatingNew: {
+ type: Boolean,
+ value: false,
+ },
+
+ showEditor: {
+ type: Boolean,
+ computed: 'computeShowEditor(automation, creatingNew)',
+ }
},
listeners: {
'hass-automation-picked': 'automationPicked',
+ 'hass-create-automation': 'createAutomation',
},
computeIsWide: function (showMenu, wideSidebar, wide) {
return showMenu ? wideSidebar : wide;
},
- computeAutomation: function (automations, automationId) {
+ computeAutomation: function (automations, automationId, creatingNew) {
+ if (creatingNew) {
+ return null;
+ }
for (var i = 0; i < automations.length; i++) {
if (automations[i].attributes.id === automationId) {
return automations[i];
@@ -126,8 +142,19 @@ Polymer({
});
},
+ computeShowEditor: function (automation, creatingNew) {
+ return creatingNew || automation;
+ },
+
automationPicked: function (ev) {
this.automationId = ev.detail.id;
- }
+ if (this.creatingNew) {
+ this.creatingNew = false;
+ }
+ },
+
+ createAutomation: function () {
+ this.creatingNew = true;
+ },
});