From a2af9d0de134ff803911c88ef5a9c1c8ea38aab5 Mon Sep 17 00:00:00 2001 From: ulic75 Date: Wed, 11 May 2022 15:00:33 -0600 Subject: [PATCH] feat: add new option `kw_decimals` (#32) --- 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 6f4318d9..20466a23 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ I recommend looking at the [Example usage section](#example-usage) to understand | -------------- | -------- | :----------: | --------------------------------------------------------------------------------------------------------------------------------------- | | type | `string` | **required** | `custom:power-flow-card`. | | entities | `object` | **required** | One or more sensor entities, see [entities object](#entities-object) for additional entity options. | +| kw_decimals | `number` | 1 | Number of decimals rounded to when kilowatts 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 0caad2a2..04859ecd 100644 --- a/src/power-flow-card-config.ts +++ b/src/power-flow-card-config.ts @@ -17,6 +17,7 @@ export interface PowerFlowCardConfig extends LovelaceCardConfig { }; solar?: string; }; + kw_decimals: number; min_flow_rate: number; max_flow_rate: number; watt_threshold: number; diff --git a/src/power-flow-card.ts b/src/power-flow-card.ts index 2ad3dc70..caa8f645 100644 --- a/src/power-flow-card.ts +++ b/src/power-flow-card.ts @@ -21,6 +21,7 @@ import { PowerFlowCardConfig } from "./power-flow-card-config.js"; import { coerceNumber, roundValue } from "./utils.js"; const CIRCLE_CIRCUMFERENCE = 238.76104; +const KW_DECIMALS = 1; const MAX_FLOW_RATE = 6; const MIN_FLOW_RATE = 0.75; @@ -38,6 +39,7 @@ export class PowerFlowCard extends LitElement { setConfig(config: PowerFlowCardConfig): void { this._config = { ...config, + kw_decimals: coerceNumber(config.kw_decimals, KW_DECIMALS), min_flow_rate: config.min_flow_rate ?? MIN_FLOW_RATE, max_flow_rate: config.max_flow_rate ?? MAX_FLOW_RATE, watt_threshold: config.watt_threshold ?? 0, @@ -71,7 +73,7 @@ export class PowerFlowCard extends LitElement { private displayValue = (value: number) => value >= coerceNumber(this._config?.watt_threshold, 0) - ? `${roundValue(value / 1000, 1)} kW` + ? `${roundValue(value / 1000, this._config!.kw_decimals!)} kW` : `${roundValue(value, 1)} W`; protected render(): TemplateResult {