Skip to content

Commit

Permalink
feat: watt decimals can be configured via w_decimals option (ulic75#52)
Browse files Browse the repository at this point in the history
* feat: watt decimals can be configured via `w_decimals` option

closes ulic75#45

* update readme
  • Loading branch information
ulic75 authored May 18, 2022
1 parent 4c0821f commit c15a375
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 @@ -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. |
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 @@ -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;
}
4 changes: 3 additions & 1 deletion src/power-flow-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
};
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c15a375

Please sign in to comment.