Skip to content

Commit

Permalink
fix: show Wh units as integer closes #538
Browse files Browse the repository at this point in the history
  • Loading branch information
slipx06 committed Dec 8, 2024
1 parent 10ddfc1 commit 2c05d92
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sunsynk-power-flow-card",
"version": "6.1.5",
"version": "6.1.6",
"description": "A customizable Home Assistant card to emulate the Sunsynk System flow that's displayed on the Inverter screen.",
"main": "sunsynk-power-flow-card.js",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {unitOfEnergyConversionRules, UnitOfEnergyOrPower, UnitOfPower} from '../const';
import { navigate } from 'custom-card-helpers';''
import {unitOfEnergyConversionRules, UnitOfEnergyOrPower, UnitOfPower, UnitOfEnergy} from '../const';
import { navigate } from 'custom-card-helpers';

export class Utils {
static toNum(val: string | number, decimals: number = -1, invert: boolean = false): number {
Expand Down Expand Up @@ -39,6 +39,10 @@ export class Utils {
const rules = unitOfEnergyConversionRules[unit];
if (!rules) return `${numberValue.toFixed(decimal)} ${unit}`;

if (unit === UnitOfEnergy.WATT_HOUR && Math.abs(numberValue) < 1000) {
return `${Math.round(numberValue)} ${unit}`;
};

if (unit === UnitOfPower.WATT && Math.abs(numberValue) < 1000) {
return `${Math.round(numberValue)} ${unit}`;
};
Expand Down

0 comments on commit 2c05d92

Please sign in to comment.