Skip to content

Commit

Permalink
Merge pull request #27 from Codegnosis/develop
Browse files Browse the repository at this point in the history
fix - use correct UoM for battery power
  • Loading branch information
Codegnosis authored Jan 22, 2024
2 parents e1ba9e0 + 2a187ae commit 2e60f55
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 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: 4 additions & 4 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,23 +191,23 @@ export class GivTCPBatteryCardEditor extends LitElement implements LovelaceCardE
},
{
name: 'use_custom_dod',
label: 'EXPERIMENTAL! Use custom DoD to override GivTCP battery capacity value.',
label: 'Use custom DoD to override GivTCP battery capacity value.',
default: defaults.use_custom_dod,
selector: {
boolean: {}
}
},
{
name: 'display_custom_dod_stats',
label: 'EXPERIMENTAL! Display the custom DOD stats',
label: 'Display the custom DOD stats',
default: defaults.display_custom_dod_stats,
selector: {
boolean: {}
}
},
{
name: 'custom_dod',
label: 'EXPERIMENTAL! Custom DoD as percentage to override GivTCP battery capacity value.',
label: 'Custom DoD as percentage to override GivTCP battery capacity value.',
default: defaults.custom_dod,
selector: {
number: {
Expand All @@ -220,7 +220,7 @@ export class GivTCPBatteryCardEditor extends LitElement implements LovelaceCardE
},
{
name: 'calculate_reserve_from_dod',
label: 'EXPERIMENTAL! Use custom DoD to calculate the battery reserve value',
label: 'Use custom DoD to calculate the battery reserve value',
default: defaults.calculate_reserve_from_dod,
selector: {
boolean: {}
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 2e60f55

Please sign in to comment.