From 2dbd631c2699b0dcd3a29d69a4cac694782c21fa Mon Sep 17 00:00:00 2001 From: X-Ryl669 Date: Wed, 11 Jan 2023 16:49:14 +0100 Subject: [PATCH] fix: Rename back to value_multiplier --- README.md | 4 ++-- src/buildConfig.js | 2 +- src/main.js | 24 ++++++++++++------------ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index cecbd1f..d014c51 100755 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ properties of the Entity object detailed in the following table (as per `sensor. | y_axis | string | | If 'secondary', displays using the secondary y-axis on the right. | fixed_value | boolean | | Set to true to graph the entity's current state as a fixed value instead of graphing its state history. | smoothing | boolean | | Override for a flag indicating whether to make graph line smooth. -| scale_factor | number | 1 | Set a scale factor to use on the graph's value +| value_multiplier | number | 1 | Set a scale factor to use on the graph's value | value_factor | number | 0 | (DEPRECATED) Scale value by order of magnitude (e.g. convert Watts to kilo Watts), use negative value to scale down. ```yaml @@ -149,7 +149,7 @@ entities: - entity: sensor.pressure name: Pressure show_state: true - scale_factor: -2.1 + value_multiplier: -2.1 - sensor.humidity ``` diff --git a/src/buildConfig.js b/src/buildConfig.js index 30a123c..5e5be71 100755 --- a/src/buildConfig.js +++ b/src/buildConfig.js @@ -129,7 +129,7 @@ export default (config) => { state_map: [], cache: true, value_factor: 0, - scale_factor: 1, + value_multiplier: 1, tap_action: { action: 'more-info', }, diff --git a/src/main.js b/src/main.js index 023feb0..374e971 100755 --- a/src/main.js +++ b/src/main.js @@ -122,7 +122,7 @@ class MiniGraphCard extends LitElement { !entity.entity.startsWith('binary_sensor.'), // turn off for binary sensor by default ), logarithmic: this.config.logarithmic, - scaleFactor: (entity.scale_factor ? entity.scale_factor : 1) + scaleFactor: (entity.value_multiplier ? entity.value_multiplier : 1) * (entity.value_factor ? 10 ** entity.value_factor : valueFactor), }), ); @@ -295,7 +295,7 @@ class MiniGraphCard extends LitElement { style=${entityConfig.state_adaptive_color ? `color: ${this.computeColor(state, id)};` : ''}> ${entityConfig.show_indicator ? this.renderIndicator(state, id) : ''} - ${this.computeState(isPrimary && tooltipValue || state, entityConfig.scale_factor)} + ${this.computeState(isPrimary && tooltipValue || state, entityConfig.value_multiplier)} ${this.computeUom(isPrimary && entity || id)} @@ -580,7 +580,7 @@ class MiniGraphCard extends LitElement {
${entry.type} - ${this.computeState(entry.state, entry.scale_factor)} ${this.computeUom(0)} + ${this.computeState(entry.state, entry.value_multiplier)} ${this.computeUom(0)} ${entry.type !== 'avg' ? getTime(new Date(entry.last_changed), this.config.format, this._hass.language) : ''} @@ -682,7 +682,7 @@ class MiniGraphCard extends LitElement { ); } - computeState(inState, default_scale_factor) { + computeState(inState, default_value_multiplier) { if (this.config.state_map.length > 0) { const stateMap = Number.isInteger(inState) ? this.config.state_map[inState] @@ -703,16 +703,16 @@ class MiniGraphCard extends LitElement { } const dec = this.config.decimals; const value_factor = 10 ** this.config.value_factor; - const scale_factor = default_scale_factor || this.config.scale_factor || 1; + const value_multiplier = default_value_multiplier || this.config.value_multiplier || 1; if (dec === undefined || Number.isNaN(dec) || Number.isNaN(state)) { - return this.numberFormat((Math.round(state * value_factor * scale_factor * 100) / 100), + return this.numberFormat((Math.round(state * value_factor * value_multiplier * 100) / 100), this._hass.language); } const x = 10 ** dec; return this.numberFormat( - (Math.round(state * value_factor * x * scale_factor) / x).toFixed(dec), + (Math.round(state * value_factor * x * value_multiplier) / x).toFixed(dec), this._hass.language, dec, ); } @@ -945,7 +945,7 @@ class MiniGraphCard extends LitElement { if (stateHistory.length === 0) return; if (this.entity[0] && entity.entity_id === this.entity[0].entity_id) { - this.updateExtrema(stateHistory, this.config.entities[index].scale_factor || 1); + this.updateExtrema(stateHistory, this.config.entities[index].value_multiplier || 1); } if (this.config.entities[index].fixed_value === true) { @@ -967,22 +967,22 @@ class MiniGraphCard extends LitElement { return this._hass.callApi('GET', url); } - updateExtrema(history, scale_factor) { + updateExtrema(history, value_multiplier) { const { extrema, average } = this.config.show; this.abs = [ ...(extrema ? [{ type: 'min', - scale_factor, + value_multiplier, ...getMin(history, 'state'), }] : []), ...(average ? [{ type: 'avg', - scale_factor, + value_multiplier, state: getAvg(history, 'state'), }] : []), ...(extrema ? [{ type: 'max', - scale_factor, + value_multiplier, ...getMax(history, 'state'), }] : []), ];