Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add new option kw_decimals #32

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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