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

add kilo<0-9> and mega<0-9> formats #344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## 4.5.2

**Added:**
- format kilo#, where # is number of digits
- format mega#, where # is number of digits

## 4.5.1

**Fixed:**
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ The `format` option supports the following values:
| duration-h | `number` | Convert number of hours to duration (`5:38:50`) |
| invert | `number` | Convert number from positive to negative or vice versa |
| kilo | `number` | Divide number value by 1000 (ex. `1500 W` -> `1.5 kW`) |
| kilo<0-9> | `number` | Divide number value by 1000 and set decimal precision |
| mega<0-9> | `number` | Divide number value by 1000000 and set decimal precision |
| position | `number` | Reverses a position percentage (ex. `70%` open -> `30%` closed) |
| precision<0-9> | `number` | Set decimal precision of number value (`precision3` -> `18.123`) |
| celsius_to_fahrenheit | `number` | Converts a Celsius temperature to its Fahrenheit equivalent |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "multiple-entity-row",
"version": "4.5.1",
"version": "4.5.2",
"description": "Show multiple entity states, attributes and icons on entity rows in Home Assistant's Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
12 changes: 12 additions & 0 deletions src/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ export const entityStateDisplay = (hass, stateObj, config) => {
});
} else if (config.format === 'kilo') {
value = formatNumber(value / 1000, hass.locale, { maximumFractionDigits: 2 });
} else if (config.format.startsWith('kilo')) {
const precision = parseInt(config.format.slice(-1), 5);
value = formatNumber(parseFloat(value)/1000, hass.locale, {
minimumFractionDigits: precision,
maximumFractionDigits: precision,
});
} else if (config.format.startsWith('mega')) {
const precision = parseInt(config.format.slice(-1), 5);
value = formatNumber(parseFloat(value)/1000000, hass.locale, {
minimumFractionDigits: precision,
maximumFractionDigits: precision,
});
} else if (config.format === 'invert') {
value = formatNumber(value - value * 2, hass.locale);
} else if (config.format === 'position') {
Expand Down