Skip to content

Commit aafc04a

Browse files
committed
Fixes for layout when not using PV or Battery
1 parent 984c1ea commit aafc04a

File tree

1 file changed

+17
-41
lines changed

1 file changed

+17
-41
lines changed

compact-power-card.js

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,36 +1056,10 @@ class CompactPowerCard extends (window.LitElement ||
10561056
ha-card.no-pv .canvas,
10571057
:host(.no-battery) .canvas,
10581058
ha-card.no-battery .canvas {
1059-
margin-top: 0px;
1059+
margin-top: -12px;
10601060
margin-bottom: 0px;
10611061
}
10621062
1063-
:host(.no-pv).has-single-side-label .canvas,
1064-
ha-card.no-pv.has-single-side-label .canvas,
1065-
:host(.no-battery).has-single-side-label .canvas,
1066-
ha-card.no-battery.has-single-side-label .canvas {
1067-
margin-top: -20px;
1068-
}
1069-
1070-
:host(.no-pv):not(.has-pv-labels):not(.has-grid-labels):not(.has-battery-labels) .canvas,
1071-
ha-card.no-pv:not(.has-pv-labels):not(.has-grid-labels):not(.has-battery-labels) .canvas,
1072-
:host(.no-battery):not(.has-pv-labels):not(.has-grid-labels):not(.has-battery-labels) .canvas,
1073-
ha-card.no-battery:not(.has-pv-labels):not(.has-grid-labels):not(.has-battery-labels) .canvas {
1074-
margin-top: -40px;
1075-
margin-bottom: 0px;
1076-
}
1077-
1078-
:host(.no-pv),
1079-
:host(.no-battery) {
1080-
height: auto;
1081-
}
1082-
1083-
ha-card.no-pv,
1084-
ha-card.no-battery {
1085-
height: auto;
1086-
}
1087-
1088-
10891063
:host(.no-battery) #line-pv-battery,
10901064
:host(.no-battery) #line-home-battery,
10911065
:host(.no-battery) #arc-grid-battery,
@@ -1199,27 +1173,33 @@ class CompactPowerCard extends (window.LitElement ||
11991173
this._lastRowSize = rowSize;
12001174
}
12011175

1176+
_shouldUseExternalHeight() {
1177+
return Boolean(this.closest("div.card.fit-rows"));
1178+
}
1179+
12021180
_getLayoutMetrics({ hasPv, hasBattery, hasAnyLabels }) {
12031181
const designWidth = 512;
12041182
const designHeight = 184;
12051183
const defaultWidth = 512;
1206-
const defaultHeight = 184;
1184+
const useExternalHeight = this._shouldUseExternalHeight();
1185+
const defaultHeight = !useExternalHeight && (!hasPv || !hasBattery) ? 150 : 184;
12071186
const hostRect = this.getBoundingClientRect ? this.getBoundingClientRect() : null;
12081187
const outerWidth = this._hostWidth != null ? this._hostWidth : hostRect?.width || defaultWidth;
1209-
const outerHeight =
1210-
this._externalHeight != null
1188+
const outerHeight = useExternalHeight
1189+
? this._externalHeight != null
12111190
? this._externalHeight
12121191
: this._hostHeight != null
12131192
? this._hostHeight
1214-
: hostRect?.height || defaultHeight;
1193+
: hostRect?.height || defaultHeight
1194+
: defaultHeight;
12151195
const padX = 8; // ha-card left+right padding (4px each)
12161196
const padY = 2; // bottom padding; top is 0
12171197
const baseWidth = Math.max(0, outerWidth - padX);
1218-
const hasExternalHeight = outerHeight > defaultHeight + 32; // require meaningful external height to avoid slow creep
1219-
const compactTrim = (!hasPv || !hasBattery) && !hasAnyLabels ? 20 : 0;
1198+
const hasExternalHeight = useExternalHeight && (this._externalHeight != null || this._hostHeight != null);
1199+
const compactTrim = 0;
12201200
const baseHeight = hasExternalHeight
12211201
? Math.max(0, outerHeight - padY - compactTrim)
1222-
: Math.max(0, designHeight - compactTrim);
1202+
: Math.max(0, outerHeight - padY - compactTrim);
12231203
const renderScaleY = baseHeight > 0 ? (outerHeight - padY) / baseHeight : 1;
12241204
const xScale = baseWidth / designWidth;
12251205
const yScale = baseHeight / designHeight;
@@ -1420,12 +1400,7 @@ class CompactPowerCard extends (window.LitElement ||
14201400
this._hostWidth = newW;
14211401
this._hostHeight = newH;
14221402
const widthChanged = prevW != null && newW !== prevW;
1423-
if (this._externalHeight == null) {
1424-
this._externalHeight = newH;
1425-
} else if (widthChanged || newH < this._externalHeight - 24) {
1426-
// Only trust height updates when the card width changes or on meaningful shrink.
1427-
this._externalHeight = newH;
1428-
}
1403+
this._externalHeight = newH;
14291404
if (prevW == null || prevH == null) {
14301405
this.requestUpdate();
14311406
}
@@ -3147,6 +3122,7 @@ class CompactPowerCard extends (window.LitElement ||
31473122
batteryNode,
31483123
homeNode,
31493124
} = layout;
3125+
const deviceYOffset = this._shouldUseExternalHeight() && rowCount < 3 ? 20 : 0;
31503126
const labelBonus = !hasPv || !hasBattery ? (rowCount >= 4 ? 2 : 1) : 0;
31513127
const gridBatteryBonus =
31523128
hasPv && hasBattery && pvLabels.length <= 4
@@ -3458,7 +3434,7 @@ class CompactPowerCard extends (window.LitElement ||
34583434
const cornerBaseRadius = pvGridTurnRadius;
34593435
const sourcePositions = [];
34603436
const homeX = homeCenterX;
3461-
const homeRowYBase = 145; // base Y for aux row; actual Y will be adjusted via pctHomeY
3437+
const homeRowYBase = 145 + deviceYOffset; // base Y for aux row; actual Y will be adjusted via pctHomeY
34623438

34633439
const deviceFlickerMs = 500;
34643440
const deviceFlickerNow = Date.now();

0 commit comments

Comments
 (0)