Skip to content

Commit

Permalink
Merge pull request #37 from flixlix/quickfix-white-space
Browse files Browse the repository at this point in the history
feat & bug: fixed bug with missing white space
  • Loading branch information
flixlix authored Mar 28, 2023
2 parents be32b06 + 66a5e54 commit 63d7822
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ 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`.
| 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. |

### Minimal Configuration

Expand Down
22 changes: 17 additions & 5 deletions src/power-flow-card-plus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ export class PowerFlowCardPlus extends LitElement {
return result;
};

private displayValue = (value: number | null, unit?: string | undefined) => {
private displayValue = (
value: number | null,
unit?: string | undefined,
unitWhiteSpace?: boolean | undefined
) => {
if (value === null) return "0";
const isKW = unit === undefined && value >= this._config!.watt_threshold;
const v = formatNumber(
Expand All @@ -149,7 +153,9 @@ export class PowerFlowCardPlus extends LitElement {
: round(value, this._config!.w_decimals),
this.hass.locale
);
return `${v}${unit || (isKW ? "kW" : "W")}`;
return `${v}${unitWhiteSpace === false ? "" : " "}${
unit || (isKW ? "kW" : "W")
}`;
};

private openDetails(entityId?: string | undefined): void {
Expand Down Expand Up @@ -749,7 +755,9 @@ export class PowerFlowCardPlus extends LitElement {
${this.displayValue(
individual2SecondaryUsage,
entities.individual2?.secondary_info
?.unit_of_measurement
?.unit_of_measurement,
entities.individual2?.secondary_info
?.unit_white_space
)}
</span>
`
Expand Down Expand Up @@ -823,7 +831,9 @@ export class PowerFlowCardPlus extends LitElement {
${this.displayValue(
individual1SecondaryUsage,
entities.individual1?.secondary_info
?.unit_of_measurement
?.unit_of_measurement,
entities.individual1?.secondary_info
?.unit_white_space
)}
</span>
`
Expand Down Expand Up @@ -1275,7 +1285,9 @@ export class PowerFlowCardPlus extends LitElement {
${this.displayValue(
individual1SecondaryUsage,
entities.individual1?.secondary_info
?.unit_of_measurement
?.unit_of_measurement,
entities.individual1?.secondary_info
?.unit_white_space
)}
</span>
`
Expand Down
1 change: 1 addition & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type IndividualDeviceType = {
unit_of_measurement?: string;
icon?: string;
display_zero?: boolean;
unit_white_space?: boolean;
};
};

Expand Down

0 comments on commit 63d7822

Please sign in to comment.