Skip to content

Commit

Permalink
Merge pull request #75 from JonahKr/dev
Browse files Browse the repository at this point in the history
Hotfix #74 unit of measurement ignored
  • Loading branch information
JonahKr authored Jul 4, 2021
2 parents a52b452 + 8485d3c commit 84f79fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "power-distribution-card",
"version": "2.3.0",
"version": "2.3.1",
"license": "MIT",
"author": "JonahKr",
"description": "A Lovelace Card for visualizing power distributions.",
Expand Down
7 changes: 4 additions & 3 deletions src/power-distribution-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class PowerDistributionCard extends LitElement {
//Resize Observer
this._adjustWidth();
this._attachObserver();
//This is needed to prevent Rendering without the unit_of_measurements
this.requestUpdate();
}

protected updated(changedProps: PropertyValues): void {
Expand Down Expand Up @@ -167,7 +169,7 @@ export class PowerDistributionCard extends LitElement {
private _val(item: EntitySettings | BarSettings): number {
let modifier = item.invert_value ? -1 : 1;
//Proper K Scaling e.g. 1kW = 1000W
if ((item as EntitySettings).unit_of_measurement?.startsWith('k')) modifier *= 1000;
if (item.unit_of_measurement?.charAt(0) == 'k') modifier *= 1000;
//Checking if an attribute was defined to pull the value from
const attr = (item as EntitySettings).attribute || null;
// If an entity exists, check if the attribute setting is entered -> value from attribute else value from entity
Expand Down Expand Up @@ -274,10 +276,9 @@ export class PowerDistributionCard extends LitElement {
const state = item.invert_arrow ? value * -1 : value;
//Toggle Absolute Values
value = item.display_abs ? Math.abs(value) : value;

//Unit-Of-Display and Unit_of_measurement
let unit_of_display = item.unit_of_display || 'W';
const uod_split = unit_of_display.split('k');
const uod_split = unit_of_display.charAt(0);
if (uod_split[0] == 'k') {
value /= 1000;
} else if (item.unit_of_display == 'adaptive') {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface BarSettings {
name?: string | undefined;
preset?: 'autarky' | 'ratio' | '';
tap_action?: ActionConfig;
unit_of_measurement?: string;
double_tap_action?: ActionConfig;
}

Expand Down

0 comments on commit 84f79fb

Please sign in to comment.