Skip to content

Commit db09957

Browse files
authored
Fixes for 1.3.2.6
## Added - Card-level `remove_glow_effects` option to disable glow/drop-shadow effects in dark mode. ## Fixed - Issue where some labels in numerical formats like "23:00:00" were being rendered as decimals.
1 parent f088ba2 commit db09957

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

compact-power-card.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,14 @@ class CompactPowerCard extends (window.LitElement ||
16971697
return v == null ? 0 : v;
16981698
}
16991699

1700+
_getNumericMaybe(entityId, attribute = null) {
1701+
if (!this.hass || !entityId) return null;
1702+
const st = this.hass.states[entityId];
1703+
if (!st) return null;
1704+
const raw = attribute ? st.attributes?.[attribute] : st.state;
1705+
return this._parseNumberStrict(raw);
1706+
}
1707+
17001708
_getPowerMeta(entityId, unitOverride = null, attribute = null) {
17011709
const value = this._getNumeric(entityId, attribute);
17021710
const unit =
@@ -2885,21 +2893,22 @@ class CompactPowerCard extends (window.LitElement ||
28852893
const name = src.name || null;
28862894
const icon = src.icon || this._getEntityIcon(entity, "mdi:power-plug");
28872895
const isPowerDevice = this._isPowerDevice(entity);
2888-
const numeric = this._getNumeric(entity, attribute);
2896+
const numeric = this._getNumericMaybe(entity, attribute);
28892897
const unit =
28902898
this.hass?.states?.[entity]?.attributes?.unit_of_measurement ||
28912899
"";
28922900
const decimals = this._getDecimalPlaces(src);
2893-
const numericW = this._toWatts(numeric, unit);
2901+
const numericW = this._toWatts(numeric, unit, true);
2902+
const hasNumeric = Number.isFinite(numericW);
28942903
const unitOverride = this._getUnitOverride(src);
2895-
let val = Number.isFinite(numericW)
2904+
let val = hasNumeric
28962905
? this._formatPowerWithOverride(numericW, decimals, "W", unitOverride ?? null)
28972906
: this._formatEntity(entity, decimals, attribute, unitOverride);
28982907
const color = src.color || homeColor;
28992908
const threshold = this._toWatts(this._parseThreshold(src.threshold), "W", true);
2900-
const opacity = this._opacityFor(numericW, threshold);
2909+
const opacity = hasNumeric ? this._opacityFor(numericW, threshold) : 1;
29012910
const hidden =
2902-
this._isBelowThreshold(numericW, threshold) ||
2911+
(hasNumeric && this._isBelowThreshold(numericW, threshold)) ||
29032912
(this._coerceBoolean(src.force_hide_under_threshold, false) && numericW === 0);
29042913
const forceHideUnderThreshold = this._coerceBoolean(src.force_hide_under_threshold, false);
29052914
let switchOn = false;
@@ -2918,7 +2927,7 @@ class CompactPowerCard extends (window.LitElement ||
29182927
color,
29192928
opacity,
29202929
hidden,
2921-
numeric: numericW,
2930+
numeric: hasNumeric ? numericW : 0,
29222931
isPowerDevice,
29232932
threshold,
29242933
forceHideUnderThreshold,
@@ -3054,17 +3063,18 @@ class CompactPowerCard extends (window.LitElement ||
30543063
const unitOverride = this._getUnitOverride(lbl);
30553064
const icon = lbl.icon || this._getLabelIcon(entity, attribute, "mdi:tag-text-outline");
30563065
const color = lbl.color || pvColor;
3057-
const numeric = this._getNumeric(entity, attribute);
3066+
const numeric = this._getNumericMaybe(entity, attribute);
30583067
const decimals = this._getDecimalPlaces(lbl);
30593068
const val = this._formatEntity(entity, decimals, attribute, unitOverride);
30603069
const labelUnit =
30613070
unitOverride ||
30623071
this.hass?.states?.[entity]?.attributes?.unit_of_measurement ||
30633072
"";
3064-
const numericW = this._toWatts(numeric, labelUnit);
3073+
const numericW = this._toWatts(numeric, labelUnit, true);
3074+
const hasNumeric = Number.isFinite(numericW);
30653075
const threshold = this._toWatts(this._parseThreshold(lbl.threshold), "W", true);
3066-
const opacity = numericW === 0 ? 1 : this._opacityFor(numericW, threshold);
3067-
const hidden = this._isBelowThreshold(numericW, threshold);
3076+
const opacity = hasNumeric ? (numericW === 0 ? 1 : this._opacityFor(numericW, threshold)) : 1;
3077+
const hidden = hasNumeric ? this._isBelowThreshold(numericW, threshold) : false;
30683078
const posMeta = pvLabelPositions[idx] || pvLabelPositions[pvLabelPositions.length - 1];
30693079
const leftPct = (posMeta.x / baseWidth) * 100;
30703080
const yPct = pctBaseY(pvLabelY); // PV stays fixed in Y
@@ -3078,7 +3088,7 @@ class CompactPowerCard extends (window.LitElement ||
30783088
hidden,
30793089
leftPct,
30803090
topPct: yPct,
3081-
numeric: numericW,
3091+
numeric: hasNumeric ? numericW : 0,
30823092
};
30833093
});
30843094

@@ -3094,17 +3104,18 @@ class CompactPowerCard extends (window.LitElement ||
30943104
const unitOverride = this._getUnitOverride(lbl);
30953105
const icon = lbl.icon || this._getLabelIcon(entity, attribute, "mdi:tag-text-outline");
30963106
const color = lbl.color || gridColor;
3097-
const numeric = this._getNumeric(entity, attribute);
3107+
const numeric = this._getNumericMaybe(entity, attribute);
30983108
const decimals = this._getDecimalPlaces(lbl);
30993109
const val = this._formatEntity(entity, decimals, attribute, unitOverride);
31003110
const labelUnit =
31013111
unitOverride ||
31023112
this.hass?.states?.[entity]?.attributes?.unit_of_measurement ||
31033113
"";
3104-
const numericW = this._toWatts(numeric, labelUnit);
3114+
const numericW = this._toWatts(numeric, labelUnit, true);
3115+
const hasNumeric = Number.isFinite(numericW);
31053116
const threshold = this._toWatts(this._parseThreshold(lbl.threshold), "W", true);
3106-
const opacity = numericW === 0 ? 1 : this._opacityFor(numericW, threshold);
3107-
const hidden = this._isBelowThreshold(numericW, threshold);
3117+
const opacity = hasNumeric ? (numericW === 0 ? 1 : this._opacityFor(numericW, threshold)) : 1;
3118+
const hidden = hasNumeric ? this._isBelowThreshold(numericW, threshold) : false;
31083119
const pos = gridLabelPositions[idx] || gridLabelPositions[gridLabelPositions.length - 1];
31093120
return {
31103121
entity,
@@ -3115,7 +3126,7 @@ class CompactPowerCard extends (window.LitElement ||
31153126
hidden,
31163127
xPct: pos.xPct,
31173128
yPx: pos.yPx,
3118-
numeric: numericW,
3129+
numeric: hasNumeric ? numericW : 0,
31193130
};
31203131
});
31213132

@@ -3129,17 +3140,18 @@ class CompactPowerCard extends (window.LitElement ||
31293140
const unitOverride = this._getUnitOverride(lbl);
31303141
const icon = lbl.icon || this._getLabelIcon(entity, attribute, "mdi:tag-text-outline");
31313142
const color = lbl.color || batteryColor;
3132-
const numeric = this._getNumeric(entity, attribute);
3143+
const numeric = this._getNumericMaybe(entity, attribute);
31333144
const decimals = this._getDecimalPlaces(lbl);
31343145
const val = this._formatEntity(entity, decimals, attribute, unitOverride);
31353146
const labelUnit =
31363147
unitOverride ||
31373148
this.hass?.states?.[entity]?.attributes?.unit_of_measurement ||
31383149
"";
3139-
const numericW = this._toWatts(numeric, labelUnit);
3150+
const numericW = this._toWatts(numeric, labelUnit, true);
3151+
const hasNumeric = Number.isFinite(numericW);
31403152
const threshold = this._toWatts(this._parseThreshold(lbl.threshold), "W", true);
3141-
const opacity = this._opacityFor(numericW, threshold);
3142-
const hidden = this._isBelowThreshold(numericW, threshold);
3153+
const opacity = hasNumeric ? this._opacityFor(numericW, threshold) : 1;
3154+
const hidden = hasNumeric ? this._isBelowThreshold(numericW, threshold) : false;
31433155
const pos = batteryLabelPositions[idx] || batteryLabelPositions[batteryLabelPositions.length - 1];
31443156
return {
31453157
entity,
@@ -3150,7 +3162,7 @@ class CompactPowerCard extends (window.LitElement ||
31503162
hidden,
31513163
xPct: pos.xPct,
31523164
yPx: pos.yPx,
3153-
numeric: numericW,
3165+
numeric: hasNumeric ? numericW : 0,
31543166
};
31553167
});
31563168

0 commit comments

Comments
 (0)