diff --git a/CHANGELOG.md b/CHANGELOG.md index 7519481..8bfd560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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:** diff --git a/README.md b/README.md index 6decc00..d8c4e8c 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/package.json b/package.json index 28a6d7b..9c7d754 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/entity.js b/src/entity.js index c415833..e87d712 100644 --- a/src/entity.js +++ b/src/entity.js @@ -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') {