Skip to content

Commit

Permalink
Merge pull request #31 from Codegnosis/develop
Browse files Browse the repository at this point in the history
Check misconfiguration & add debug output config option
  • Loading branch information
Codegnosis committed Mar 18, 2024
2 parents f9366c4 + 70bc233 commit 15a3aef
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Edit your chosen dashboard and use the "Add Card" button to select the "GivTCP B

```yaml
type: custom:givtcp-battery-card
entity: sensor.givetcp_abc123_invertor_serial_number
entity: sensor.givtcp_abc123_invertor_serial_number
name: Battery
soc_threshold_very_high: 80
soc_threshold_high: 60
Expand Down
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.2",
"version": "0.2.3",
"description": "Lovelace card to display GivTCP battery info",
"private": true,
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
DISPLAY_BATTERY_RATES,
USE_CUSTOM_DOD,
CUSTOM_DOD,
CALCULATE_RESERVE_FROM_DOD, DISPLAY_CUSTOM_DOD_STATS,
CALCULATE_RESERVE_FROM_DOD, DISPLAY_CUSTOM_DOD_STATS, ENABLE_DEBUG_OUTPUT,
} from "./constants";

export class ConfigUtils {
Expand Down Expand Up @@ -47,6 +47,7 @@ export class ConfigUtils {
custom_dod: CUSTOM_DOD,
calculate_reserve_from_dod: CALCULATE_RESERVE_FROM_DOD,
display_custom_dod_stats: DISPLAY_CUSTOM_DOD_STATS,
enable_debug_output: ENABLE_DEBUG_OUTPUT,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ export const DISPLAY_UNITS = {
WH: "Wh",
KWH: "kWh",
}

export const ENABLE_DEBUG_OUTPUT = false;
24 changes: 23 additions & 1 deletion src/givtcp-battery-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard {
displayUnit: "%",
}

if(this.config.enable_debug_output === true) {
console.log(states);
}

this.calculatedStates = states;
}

Expand Down Expand Up @@ -609,6 +613,19 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard {
return html``;
}

// first check it's actually in invertor. Checking for the invertor_power entity should suffice
// as currently GivTCP only creates this entity for invertors
const invertorExists = this._getInvertorPower
if(invertorExists === undefined) {
return html`
<ha-card>
<div class="preview">
<p>Could not find invertor ${this.config.entity}. Please check your config and ensure you are adding
the invertor's serial sensor.</p>
</div>
</ha-card>`;
}

let batteryRateData = html``;
const displayBatteryRates = (this.config.display_battery_rates !== undefined) ? this.config.display_battery_rates : DISPLAY_BATTERY_RATES;

Expand Down Expand Up @@ -749,8 +766,13 @@ export class GivTCPBatteryCard extends LitElement implements LovelaceCard {
return this.hass.states[`number.${this._getSensorPrefix}battery_discharge_rate`];
}

private get _getInvertorPower(): HassEntity {
return this.hass.states[`sensor.${this._getSensorPrefix}invertor_power`];
}

private get _getBatteryStatus(): string {
const power = parseInt(this._getBatteryPowerEntity.state, 10);

const power = this.calculatedStates.batteryPower.value;

let status = '';
if (power > 0) {
Expand Down
8 changes: 8 additions & 0 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export const GENERAL_SCHEMA = (invertorList: string[], defaults: LovelaceCardCon
}
},
},
{
name: 'enable_debug_output',
label: 'Enable debug output to developer console',
default: defaults.enable_debug_output,
selector: {
boolean: {}
}
},
];
}

Expand Down

0 comments on commit 15a3aef

Please sign in to comment.