Skip to content

Commit

Permalink
fix - use correct UoM for battery power
Browse files Browse the repository at this point in the history
  • Loading branch information
Codegnosis committed Jan 22, 2024
1 parent dcf8cc9 commit 0db706b
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": "givtcp-battery-card",
"version": "0.2.0",
"version": "0.2.1",
"description": "Lovelace card to display GivTCP battery info",
"private": true,
"type": "module",
Expand Down
8 changes: 6 additions & 2 deletions src/givtcp-battery-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard {
return (uom === DISPLAY_UNITS.W || uom === DISPLAY_UNITS.WH);
}

isPowerUom(uom: string): boolean {
return (uom === DISPLAY_UNITS.W || uom === DISPLAY_UNITS.KW);
}

getGivTcpStats(state: string, uomRaw: string | undefined): GivTcpStats {
const displayType = (this.config.display_type !== undefined) ? this.config.display_type : DISPLAY_TYPE;
const displayAbsPower = (this.config.display_abs_power !== undefined) ? this.config.display_abs_power : DISPLAY_ABS_POWER;
Expand All @@ -229,8 +233,8 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard {
const kValue = this.isWorWh(uom) ? this.convertToKillo(rawAsNum, 3) : rawAsNum;
const displayK = this.convertToKillo(value, dp);

const displayUom = this.isWorWh(uom) ? uom : this.getStandardisedUom(`k${uom}`);
const displayKUom = this.isWorWh(uom) ? this.getStandardisedUom(`k${uom}`) : uom;
const displayUom = this.isPowerUom(uom) ? DISPLAY_UNITS.W : DISPLAY_UNITS.WH;
const displayKUom = this.isPowerUom(uom) ? DISPLAY_UNITS.KW : DISPLAY_UNITS.KWH;

let display = 0;
let displayStr = "";
Expand Down

0 comments on commit 0db706b

Please sign in to comment.