Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase precision for input_number and climate-controller #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}