Skip to content

Commit

Permalink
feat: add new option kw_decimals (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulic75 authored May 11, 2022
1 parent 63b473b commit a2af9d0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
1 change: 1 addition & 0 deletions src/power-flow-card-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/power-flow-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a2af9d0

Please sign in to comment.