From c15a3754a61aaccfc1f62801915902b2e64756b8 Mon Sep 17 00:00:00 2001 From: ulic75 Date: Wed, 18 May 2022 09:36:27 -0600 Subject: [PATCH] feat: watt decimals can be configured via w_decimals option (#52) * feat: watt decimals can be configured via `w_decimals` option closes #45 * update readme --- README.md | 1 + src/power-flow-card-config.ts | 1 + src/power-flow-card.ts | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b2b8f740..ce8963d8 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ I recommend looking at the [Example usage section](#example-usage) to understand | dashboard_link | `string` | | Shows a link to an Energy Dashboard. Should be a url path to location of your choice. If you wanted to link to the built-in dashboard you would enter `/energy` for example. | | inverted_entities | `string` | | Comma seperated list of entities that should be inverted (negative for consumption and positive for production). See [example usage](#inverted-entities-example). | | kw_decimals | `number` | 1 | Number of decimals rounded to when kilowatts are displayed. | +| w_decimals | `number` | 1 | Number of decimals rounded to when watts are displayed. | | min_flow_rate | `number` | .75 | Represents the fastest amount of time in seconds for a flow dot to travel from one end to the other, see [flow formula](#flow-formula). | | max_flow_rate | `number` | 6 | Represents the slowest amount of time in seconds for a flow dot to travel from one end to the other, see [flow formula](#flow-formula). | | watt_threshold | `number` | 0 | The number of watts to display before converting to and displaying kilowatts. Setting of 0 will always display in kilowatts. | diff --git a/src/power-flow-card-config.ts b/src/power-flow-card-config.ts index 96820f9c..703d3f4e 100644 --- a/src/power-flow-card-config.ts +++ b/src/power-flow-card-config.ts @@ -22,5 +22,6 @@ export interface PowerFlowCardConfig extends LovelaceCardConfig { kw_decimals: number; min_flow_rate: number; max_flow_rate: number; + w_decimals: number; watt_threshold: number; } diff --git a/src/power-flow-card.ts b/src/power-flow-card.ts index 6322d088..5bf88980 100644 --- a/src/power-flow-card.ts +++ b/src/power-flow-card.ts @@ -25,6 +25,7 @@ const CIRCLE_CIRCUMFERENCE = 238.76104; const KW_DECIMALS = 1; const MAX_FLOW_RATE = 6; const MIN_FLOW_RATE = 0.75; +const W_DECIMALS = 1; @customElement("power-flow-card") export class PowerFlowCard extends LitElement { @@ -44,6 +45,7 @@ export class PowerFlowCard extends LitElement { kw_decimals: coerceNumber(config.kw_decimals, KW_DECIMALS), min_flow_rate: coerceNumber(config.min_flow_rate, MIN_FLOW_RATE), max_flow_rate: coerceNumber(config.max_flow_rate, MAX_FLOW_RATE), + w_decimals: coerceNumber(config.w_decimals, W_DECIMALS), watt_threshold: coerceNumber(config.watt_threshold), }; } @@ -79,7 +81,7 @@ export class PowerFlowCard extends LitElement { private displayValue = (value: number) => value >= this._config!.watt_threshold ? `${round(value / 1000, this._config!.kw_decimals)} kW` - : `${round(value, 1)} W`; + : `${round(value, this._config!.w_decimals)} W`; protected render(): TemplateResult { if (!this._config || !this.hass) {