diff --git a/README.md b/README.md index 2cc8040..1ef7959 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. -| value_multipler | number | 1 | Set a multiplier to use on the graph's value +| scale_factor | number | 1 | Set a scale factor to use on the graph's value | value_factor | number | 0 | 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 - value_multipler: -2.1 + scale_factor: -2.1 - sensor.humidity ``` diff --git a/src/graph.js b/src/graph.js index f8827d0..ad074e8 100755 --- a/src/graph.js +++ b/src/graph.js @@ -12,7 +12,7 @@ export default class Graph { hours = 24, points = 1, aggregateFuncName = 'avg', - valueMultipler = 1, + scaleFactor = 1, groupBy = 'interval', smoothing = true, logarithmic = false, @@ -39,7 +39,7 @@ export default class Graph { this.points = points; this.hours = hours; this.aggregateFuncName = aggregateFuncName; - this._valueMultipler = valueMultipler; + this._scaleFactor = scaleFactor; this._calcPoint = aggregateFuncMap[aggregateFuncName] || this._average; this._smoothing = smoothing; this._logarithmic = logarithmic; @@ -111,7 +111,7 @@ export default class Graph { } _scale(value) { - return this._valueMultipler * value; + return this._scaleFactor * value; } _calcY(coords) { diff --git a/src/main.js b/src/main.js index 0aa7f43..023feb0 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, - valueMultipler: (entity.value_multipler ? entity.value_multipler : 1) + scaleFactor: (entity.scale_factor ? entity.scale_factor : 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.value_multipler)} + ${this.computeState(isPrimary && tooltipValue || state, entityConfig.scale_factor)} ${this.computeUom(isPrimary && entity || id)} @@ -580,7 +580,7 @@ class MiniGraphCard extends LitElement {
${entry.type} - ${this.computeState(entry.state, entry.value_multipler)} ${this.computeUom(0)} + ${this.computeState(entry.state, entry.scale_factor)} ${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_multiplier) { + computeState(inState, default_scale_factor) { 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 value_multipler = this.config.value_multipler || default_multiplier || 1; + const scale_factor = default_scale_factor || this.config.scale_factor || 1; if (dec === undefined || Number.isNaN(dec) || Number.isNaN(state)) { - return this.numberFormat((Math.round(state * value_factor * value_multipler * 100) / 100), + return this.numberFormat((Math.round(state * value_factor * scale_factor * 100) / 100), this._hass.language); } const x = 10 ** dec; return this.numberFormat( - (Math.round(state * value_factor * x * value_multipler) / x).toFixed(dec), + (Math.round(state * value_factor * x * scale_factor) / 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].value_multipler || 1); + this.updateExtrema(stateHistory, this.config.entities[index].scale_factor || 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, value_multipler) { + updateExtrema(history, scale_factor) { const { extrema, average } = this.config.show; this.abs = [ ...(extrema ? [{ type: 'min', - value_multipler, + scale_factor, ...getMin(history, 'state'), }] : []), ...(average ? [{ type: 'avg', - value_multipler, + scale_factor, state: getAvg(history, 'state'), }] : []), ...(extrema ? [{ type: 'max', - value_multipler, + scale_factor, ...getMax(history, 'state'), }] : []), ];