Skip to content

Commit aa65a5c

Browse files
committed
fix: Fix requested review changes
1 parent e5f1744 commit aa65a5c

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

Diff for: src/graph.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ export default class Graph {
1212
hours = 24,
1313
points = 1,
1414
aggregateFuncName = 'avg',
15-
valueFactor = 0,
16-
valueMultiplier = 1,
1715
groupBy = 'interval',
1816
smoothing = true,
19-
logarithmic = false
17+
logarithmic = false,
2018
}) {
2119
const aggregateFuncMap = {
2220
avg: this._average,
@@ -40,8 +38,6 @@ export default class Graph {
4038
this.points = points;
4139
this.hours = hours;
4240
this.aggregateFuncName = aggregateFuncName;
43-
this.valueFactor = valueFactor;
44-
this.valueMultiplier = valueMultiplier;
4541
this._calcPoint = aggregateFuncMap[aggregateFuncName] || this._average;
4642
this._smoothing = smoothing;
4743
this._logarithmic = logarithmic;

Diff for: src/main.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ class MiniGraphCard extends LitElement {
114114
hours: this.config.hours_to_show,
115115
points: this.config.points_per_hour,
116116
aggregateFuncName: entity.aggregate_func || this.config.aggregate_func,
117-
valueFactor: entity.valueFactor || this.config.valueFactor,
118-
valueMultiplier: entity.valueMultiplier || this.config.valueMultiplier,
119117
groupBy: this.config.group_by,
120118
smoothing: getFirstDefinedItem(
121119
entity.smoothing,
@@ -294,7 +292,7 @@ class MiniGraphCard extends LitElement {
294292
style=${entityConfig.state_adaptive_color ? `color: ${this.computeColor(state, id)};` : ''}>
295293
${entityConfig.show_indicator ? this.renderIndicator(state, id) : ''}
296294
<span class="state__value ellipsis">
297-
${this.computeState(isPrimary && tooltipValue || state)}
295+
${this.computeState(isPrimary && tooltipValue || state, entityConfig.value_multipler)}
298296
</span>
299297
<span class="state__uom ellipsis">
300298
${this.computeUom(isPrimary && entity || id)}
@@ -579,7 +577,7 @@ class MiniGraphCard extends LitElement {
579577
<div class="info__item">
580578
<span class="info__item__type">${entry.type}</span>
581579
<span class="info__item__value">
582-
${this.computeState(entry.state)} ${this.computeUom(0)}
580+
${this.computeState(entry.state, entry.value_multipler)} ${this.computeUom(0)}
583581
</span>
584582
<span class="info__item__time">
585583
${entry.type !== 'avg' ? getTime(new Date(entry.last_changed), this.config.format, this._hass.language) : ''}
@@ -681,7 +679,7 @@ class MiniGraphCard extends LitElement {
681679
);
682680
}
683681

684-
computeState(inState) {
682+
computeState(inState, default_multiplier) {
685683
if (this.config.state_map.length > 0) {
686684
const stateMap = Number.isInteger(inState)
687685
? this.config.state_map[inState]
@@ -702,15 +700,16 @@ class MiniGraphCard extends LitElement {
702700
}
703701
const dec = this.config.decimals;
704702
const value_factor = 10 ** this.config.value_factor;
705-
const value_multipler = this.config.value_multipler || 1;
703+
const value_multipler = this.config.value_multipler || default_multiplier || 1;
706704

707705
if (dec === undefined || Number.isNaN(dec) || Number.isNaN(state)) {
708-
return this.numberFormat(Math.round(state * value_factor * value_multiplier * 100) / 100), this._hass.language);
706+
return this.numberFormat((Math.round(state * value_factor * value_multipler * 100) / 100),
707+
this._hass.language);
709708
}
710709

711710
const x = 10 ** dec;
712711
return this.numberFormat(
713-
(Math.round(state * value_factor * x * value_multiplier) / x).toFixed(dec),
712+
(Math.round(state * value_factor * x * value_multipler) / x).toFixed(dec),
714713
this._hass.language, dec,
715714
);
716715
}
@@ -943,7 +942,7 @@ class MiniGraphCard extends LitElement {
943942
if (stateHistory.length === 0) return;
944943

945944
if (this.entity[0] && entity.entity_id === this.entity[0].entity_id) {
946-
this.updateExtrema(stateHistory);
945+
this.updateExtrema(stateHistory, this.config.entities[index].value_multipler || 1);
947946
}
948947

949948
if (this.config.entities[index].fixed_value === true) {
@@ -965,19 +964,22 @@ class MiniGraphCard extends LitElement {
965964
return this._hass.callApi('GET', url);
966965
}
967966

968-
updateExtrema(history) {
967+
updateExtrema(history, value_multipler) {
969968
const { extrema, average } = this.config.show;
970969
this.abs = [
971970
...(extrema ? [{
972971
type: 'min',
972+
value_multipler,
973973
...getMin(history, 'state'),
974974
}] : []),
975975
...(average ? [{
976976
type: 'avg',
977+
value_multipler,
977978
state: getAvg(history, 'state'),
978979
}] : []),
979980
...(extrema ? [{
980981
type: 'max',
982+
value_multipler,
981983
...getMax(history, 'state'),
982984
}] : []),
983985
];

0 commit comments

Comments
 (0)