Skip to content

Commit d0fde5e

Browse files
committed
fix: Rename value multipler to scale factor and fix config priority in compute state
1 parent 0d44609 commit d0fde5e

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ properties of the Entity object detailed in the following table (as per `sensor.
140140
| y_axis | string | | If 'secondary', displays using the secondary y-axis on the right.
141141
| fixed_value | boolean | | Set to true to graph the entity's current state as a fixed value instead of graphing its state history.
142142
| smoothing | boolean | | Override for a flag indicating whether to make graph line smooth.
143-
| value_multipler | number | 1 | Set a multiplier to use on the graph's value
143+
| scale_factor | number | 1 | Set a scale factor to use on the graph's value
144144
| value_factor | number | 0 | Scale value by order of magnitude (e.g. convert Watts to kilo Watts), use negative value to scale down.
145145

146146
```yaml
@@ -149,7 +149,7 @@ entities:
149149
- entity: sensor.pressure
150150
name: Pressure
151151
show_state: true
152-
value_multipler: -2.1
152+
scale_factor: -2.1
153153
- sensor.humidity
154154
```
155155

src/graph.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class Graph {
1212
hours = 24,
1313
points = 1,
1414
aggregateFuncName = 'avg',
15-
valueMultipler = 1,
15+
scaleFactor = 1,
1616
groupBy = 'interval',
1717
smoothing = true,
1818
logarithmic = false,
@@ -39,7 +39,7 @@ export default class Graph {
3939
this.points = points;
4040
this.hours = hours;
4141
this.aggregateFuncName = aggregateFuncName;
42-
this._valueMultipler = valueMultipler;
42+
this._scaleFactor = scaleFactor;
4343
this._calcPoint = aggregateFuncMap[aggregateFuncName] || this._average;
4444
this._smoothing = smoothing;
4545
this._logarithmic = logarithmic;
@@ -111,7 +111,7 @@ export default class Graph {
111111
}
112112

113113
_scale(value) {
114-
return this._valueMultipler * value;
114+
return this._scaleFactor * value;
115115
}
116116

117117
_calcY(coords) {

src/main.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class MiniGraphCard extends LitElement {
122122
!entity.entity.startsWith('binary_sensor.'), // turn off for binary sensor by default
123123
),
124124
logarithmic: this.config.logarithmic,
125-
valueMultipler: (entity.value_multipler ? entity.value_multipler : 1)
125+
scaleFactor: (entity.scale_factor ? entity.scale_factor : 1)
126126
* (entity.value_factor ? 10 ** entity.value_factor : valueFactor),
127127
}),
128128
);
@@ -295,7 +295,7 @@ class MiniGraphCard extends LitElement {
295295
style=${entityConfig.state_adaptive_color ? `color: ${this.computeColor(state, id)};` : ''}>
296296
${entityConfig.show_indicator ? this.renderIndicator(state, id) : ''}
297297
<span class="state__value ellipsis">
298-
${this.computeState(isPrimary && tooltipValue || state, entityConfig.value_multipler)}
298+
${this.computeState(isPrimary && tooltipValue || state, entityConfig.scale_factor)}
299299
</span>
300300
<span class="state__uom ellipsis">
301301
${this.computeUom(isPrimary && entity || id)}
@@ -580,7 +580,7 @@ class MiniGraphCard extends LitElement {
580580
<div class="info__item">
581581
<span class="info__item__type">${entry.type}</span>
582582
<span class="info__item__value">
583-
${this.computeState(entry.state, entry.value_multipler)} ${this.computeUom(0)}
583+
${this.computeState(entry.state, entry.scale_factor)} ${this.computeUom(0)}
584584
</span>
585585
<span class="info__item__time">
586586
${entry.type !== 'avg' ? getTime(new Date(entry.last_changed), this.config.format, this._hass.language) : ''}
@@ -682,7 +682,7 @@ class MiniGraphCard extends LitElement {
682682
);
683683
}
684684

685-
computeState(inState, default_multiplier) {
685+
computeState(inState, default_scale_factor) {
686686
if (this.config.state_map.length > 0) {
687687
const stateMap = Number.isInteger(inState)
688688
? this.config.state_map[inState]
@@ -703,16 +703,16 @@ class MiniGraphCard extends LitElement {
703703
}
704704
const dec = this.config.decimals;
705705
const value_factor = 10 ** this.config.value_factor;
706-
const value_multipler = this.config.value_multipler || default_multiplier || 1;
706+
const scale_factor = default_scale_factor || this.config.scale_factor || 1;
707707

708708
if (dec === undefined || Number.isNaN(dec) || Number.isNaN(state)) {
709-
return this.numberFormat((Math.round(state * value_factor * value_multipler * 100) / 100),
709+
return this.numberFormat((Math.round(state * value_factor * scale_factor * 100) / 100),
710710
this._hass.language);
711711
}
712712

713713
const x = 10 ** dec;
714714
return this.numberFormat(
715-
(Math.round(state * value_factor * x * value_multipler) / x).toFixed(dec),
715+
(Math.round(state * value_factor * x * scale_factor) / x).toFixed(dec),
716716
this._hass.language, dec,
717717
);
718718
}
@@ -945,7 +945,7 @@ class MiniGraphCard extends LitElement {
945945
if (stateHistory.length === 0) return;
946946

947947
if (this.entity[0] && entity.entity_id === this.entity[0].entity_id) {
948-
this.updateExtrema(stateHistory, this.config.entities[index].value_multipler || 1);
948+
this.updateExtrema(stateHistory, this.config.entities[index].scale_factor || 1);
949949
}
950950

951951
if (this.config.entities[index].fixed_value === true) {
@@ -967,22 +967,22 @@ class MiniGraphCard extends LitElement {
967967
return this._hass.callApi('GET', url);
968968
}
969969

970-
updateExtrema(history, value_multipler) {
970+
updateExtrema(history, scale_factor) {
971971
const { extrema, average } = this.config.show;
972972
this.abs = [
973973
...(extrema ? [{
974974
type: 'min',
975-
value_multipler,
975+
scale_factor,
976976
...getMin(history, 'state'),
977977
}] : []),
978978
...(average ? [{
979979
type: 'avg',
980-
value_multipler,
980+
scale_factor,
981981
state: getAvg(history, 'state'),
982982
}] : []),
983983
...(extrema ? [{
984984
type: 'max',
985-
value_multipler,
985+
scale_factor,
986986
...getMax(history, 'state'),
987987
}] : []),
988988
];

0 commit comments

Comments
 (0)