Skip to content

Commit

Permalink
Increase precision for input_number and climate-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jclsn committed May 31, 2024
1 parent f636283 commit 105f821
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/controllers/climate-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

}
6 changes: 5 additions & 1 deletion src/controllers/input-number-controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller } from './controller';
import { stepToPrecision } from '../utils';

export class InputNumberController extends Controller {
_targetValue;
Expand Down Expand Up @@ -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))}`;
}

}
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 105f821

Please sign in to comment.