From 38a262722715bf2527d4a169a1cca1b6a9f56633 Mon Sep 17 00:00:00 2001 From: Milan V Date: Thu, 3 Jan 2019 23:07:37 +0100 Subject: [PATCH] Fix climate control rounding error (#2375) * Fix climate rounding error * Update ha-climate-control.js --- src/components/ha-climate-control.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/ha-climate-control.js b/src/components/ha-climate-control.js index 1ca3b874c7..20c7131373 100644 --- a/src/components/ha-climate-control.js +++ b/src/components/ha-climate-control.js @@ -81,8 +81,15 @@ class HaClimateControl extends EventsMixin(PolymerElement) { this.$.target_temperature.classList.toggle("in-flux", inFlux); } + _round(val) { + // round value to precision derived from step + // insired by https://github.com/soundar24/roundSlider/blob/master/src/roundslider.js + const s = this.step.toString().split("."); + return s[1] ? parseFloat(val.toFixed(s[1].length)) : Math.round(val); + } + incrementValue() { - const newval = this.value + this.step; + const newval = this._round(this.value + this.step); if (this.value < this.max) { this.last_changed = Date.now(); this.temperatureStateInFlux(true); @@ -102,7 +109,7 @@ class HaClimateControl extends EventsMixin(PolymerElement) { } decrementValue() { - const newval = this.value - this.step; + const newval = this._round(this.value - this.step); if (this.value > this.min) { this.last_changed = Date.now(); this.temperatureStateInFlux(true);