Skip to content

Commit

Permalink
Merge pull request #44 from flixlix/display-zero-threshold
Browse files Browse the repository at this point in the history
Added Feature Display Zero Tolerance
  • Loading branch information
flixlix authored Mar 31, 2023
2 parents 27bf412 + fdb8ca6 commit e5e1963
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ At least one of _grid_, _battery_, or _solar_ is required. All entites (except _
| icon | `string` | `mdi:car-electric` or `mdi:motorbike-electric` | Icon path for the icon inside the Individual Device Circle. |
| color | `string` | `#d0cc5b` or `#964cb5` | HEX value of the color for circles labels and lines of the individual device. |
| color_icon | `boolean` | `false` | If set to `true`, icon color will match the circle's color. If set to `false`, icon color will match the text's color. |
| display_zero | `boolean` | `false` | If set to `true`, the device will be displayed even if the entity state is `0` or not a number (eg: `unavailable`). Otherwise, the non-fossil section will be hidden. |
| unit_of_measurement | `string` | `W`or `kW` (dynamic) | Sets the unit of measurement to show in the corresponding circle |
| inverted_animation |`boolean` | `false` | If set to true, the small dots will flow in the opposite direction. |
| secondary_info | `object` | `undefined` | Check [Secondary Info Object](#secondary-info-configuration)
| secondary_info | `object` | `undefined` | Check [Secondary Info Object](#secondary-info-configuration) |
| display_zero | `boolean` | `false` | If set to `true`, the device will be displayed even if the entity state is `0` or not a number (eg: `unavailable`). Otherwise, the non-fossil section will be hidden. |
| display_zero_tolerance | `number` | `0` | If set, the device will be displayed if the state is greater than the tolerance set (This is also available for the secondary info). No need to set `display_zero` property to true. |

#### Home Configuration

Expand Down Expand Up @@ -199,8 +200,9 @@ This Feature allows you to configure an additional small text for each Individua
| entity| `string` required | Entity ID providing a state value that is going to be displayed. |
| unit_of_measurement | `string` | A string to be used as the unit of measurement. (Important: don't forget surrounding string with quotes) |
| icon | `string` | An icon path to be displayed next to the state of the individual device. This is optional, meaning if you don't use this, no icon will be displayed. |
| display_zero | `boolean` | Default is `false`. If set to `true` info will still be displayed if state of the entity is `0` or `unavailable`. |
| unit_white_space | `boolean` | Default is `true`. If set to `false` will not add any whitespace between unit and state. Otherwise, white space will be added. |
| display_zero | `boolean` | Default is `false`. If set to `true` info will still be displayed if state of the entity is `0` or `unavailable`. |
| display_zero_tolerance | `number` | `0` | If set, the device will be displayed if the state is greater than the tolerance set. No need to set `display_zero` property to true. |

### Minimal Configuration

Expand Down
20 changes: 14 additions & 6 deletions src/power-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export class PowerFlowCardPlus extends LitElement {
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),
max_expected_flow_w: coerceNumber(config.max_expected_flow_w, MAX_EXPECTED_FLOW_W)
max_expected_flow_w: coerceNumber(
config.max_expected_flow_w,
MAX_EXPECTED_FLOW_W
),
};
}

Expand All @@ -81,7 +84,10 @@ export class PowerFlowCardPlus extends LitElement {
private circleRate = (value: number, total: number): number => {
const min = this._config?.min_flow_rate!;
const max = this._config?.max_flow_rate!;
return max - (value / Math.max(this._config?.max_expected_flow_w, total)) * (max - min);
return (
max -
(value / Math.max(this._config?.max_expected_flow_w, total)) * (max - min)
);
};

private getEntityState = (entity: string | undefined): number => {
Expand Down Expand Up @@ -195,17 +201,20 @@ export class PowerFlowCardPlus extends LitElement {
this.entityAvailable(entities.individual2?.entity!));
const hasIndividual2Secondary =
entities.individual2?.secondary_info?.entity !== undefined &&
(this.getEntityState(entities.individual2?.secondary_info?.entity) > 0 ||
(this.getEntityState(entities.individual2?.secondary_info?.entity) >
(entities?.individual2?.secondary_info?.display_zero_tolerance ?? 0) ||
entities.individual2.secondary_info?.display_zero === true);

const hasIndividual1 =
(entities.individual1 !== undefined &&
entities.individual1?.display_zero === true) ||
(this.getEntityStateWatts(entities.individual1?.entity) > 0 &&
(this.getEntityStateWatts(entities.individual1?.entity) >
(entities?.individual1?.display_zero_tolerance ?? 0) &&
this.entityAvailable(entities.individual1?.entity!));
const hasIndividual1Secondary =
entities.individual1?.secondary_info?.entity !== undefined &&
(this.getEntityState(entities.individual1?.secondary_info?.entity) > 0 ||
(this.getEntityState(entities.individual1?.secondary_info?.entity) >
(entities?.individual1?.secondary_info?.display_zero_tolerance ?? 0) ||
entities.individual1.secondary_info.display_zero === true);

const hasSolarProduction = entities.solar !== undefined;
Expand Down Expand Up @@ -530,7 +539,6 @@ export class PowerFlowCardPlus extends LitElement {
(solarConsumption ?? 0)) /
totalHomeConsumption);


const totalLines =
gridConsumption +
(solarConsumption ?? 0) +
Expand Down
1 change: 0 additions & 1 deletion src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type IndividualDeviceType = {
display_zero?: boolean;
unit_white_space?: boolean;
display_zero_tolerance?: number;
display-zero-threshold?: number;
};
};

Expand Down

0 comments on commit e5e1963

Please sign in to comment.