From 3fb6e001a550b9cf7255d120c3766419188ad6e5 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Sat, 11 Mar 2017 01:01:37 -0500 Subject: [PATCH] delay updates until we've stopped changing for a while. (#234) --- src/components/ha-climate-control.html | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/components/ha-climate-control.html b/src/components/ha-climate-control.html index 89633e50f1..f5c4570eb7 100644 --- a/src/components/ha-climate-control.html +++ b/src/components/ha-climate-control.html @@ -64,6 +64,7 @@ }, incrementValue: function () { var newval = this.value + this.step; + this.last_changed = Date.now(); if (newval <= this.max) { this.value = newval; } else { @@ -72,6 +73,7 @@ }, decrementValue: function () { var newval = this.value - this.step; + this.last_changed = Date.now(); if (newval >= this.min) { this.value = newval; } else { @@ -79,7 +81,23 @@ } }, valueChanged: function () { - this.fire('change'); + // when the value is changed, trigger a potential even fire in + // the future, as long as last changed is far enough in the + // past. + // + // from a UX perspective it would probably be worth changing + // font color on the temperature when it's in the flux state + // (like set to red), then animate back to black when the + // change event is fired, and the signal sent to home-assistant. + if (this.last_changed) { + window.setTimeout(function (val) { + var now = Date.now(); + if (now - val.last_changed >= 2000) { + val.fire('change'); + val.last_changed = null; + } + }, 2010, this); + } }, } );