diff --git a/src/controllers/climate-controller.ts b/src/controllers/climate-controller.ts index 6d3f4b5..79220cf 100644 --- a/src/controllers/climate-controller.ts +++ b/src/controllers/climate-controller.ts @@ -42,7 +42,7 @@ export class ClimateController extends Controller { const unit = this._hass.config.unit_system.temperature; const mode = capitalizeFirst(this.state); // const current = this.stateObj.attributes?.current_temperature ? ` | ${this.stateObj.attributes.current_temperature}${unit}` : ''; - return `${this.targetValue}${unit} | ${mode}`; + return `${this.targetValue.toFixed(1)}${unit} | ${mode}`; } } diff --git a/src/controllers/input-number-controller.ts b/src/controllers/input-number-controller.ts index 21ca5aa..6dcccf1 100644 --- a/src/controllers/input-number-controller.ts +++ b/src/controllers/input-number-controller.ts @@ -1,4 +1,5 @@ import { Controller } from './controller'; +import { stepToPrecision } from '../utils'; export class InputNumberController extends Controller { _targetValue; @@ -33,7 +34,10 @@ export class InputNumberController extends Controller { } get label(): string { - return this.stateObj.attributes.unit_of_measurement ? `${this.targetValue} ${this.stateObj.attributes.unit_of_measurement}` : `${this.targetValue}`; + return this.stateObj.attributes.unit_of_measurement ? + `${this.targetValue.toFixed(stepToPrecision(this.step))} + ${this.stateObj.attributes.unit_of_measurement}` : ` + ${this.targetValue.toFixed(stepToPrecision(this.step))}`; } } diff --git a/src/utils.ts b/src/utils.ts index b661056..d864bfb 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -61,3 +61,7 @@ export const normalize = (value: number, min: number, max: number): number => { }; export const capitalizeFirst = (s): string => (s && s[0].toUpperCase() + s.slice(1)) || ""; + +export function stepToPrecision(step: number): number { + return Math.ceil(Math.log10(step)) * -1; +}