Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout-break card with HA 2024.6 #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/layouts/base-column-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
CardConfigGroup,
CardConfig,
LovelaceCard,
HuiCard,
ColumnViewConfig,
} from "../types";
import { ResizeObserver } from "resize-observer/lib/ResizeObserver";
Expand Down Expand Up @@ -142,7 +143,7 @@ export class BaseColumnLayout extends BaseLayout {
}
}

_shouldShow(card: LovelaceCard, config: CardConfig, index: number) {
_shouldShow(card: LovelaceCard | HuiCard, config: CardConfig, index: number) {
if (!super._shouldShow(card, config, index)) return false;

if (this._config.layout?.reflow) {
Expand All @@ -156,8 +157,8 @@ export class BaseColumnLayout extends BaseLayout {
return false;
}

isBreak(card: LovelaceCard) {
return card.localName === "layout-break";
isBreak(config: CardConfig) {
return config.type === "custom:layout-break";
}

async _makeLayout() {
Expand Down
7 changes: 4 additions & 3 deletions src/layouts/base-layout.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { css, html, LitElement } from "lit";
import { property } from "lit/decorators.js";
import {
CardConfigGroup,
CardConfig,
CardConfigGroup,
HuiCard,
LovelaceCard,
ViewConfig,
} from "../types";

export class BaseLayout extends LitElement {
@property() cards: Array<LovelaceCard> = [];
@property() cards: Array<LovelaceCard | HuiCard> = [];
@property() index: number;
@property() narrow: boolean;
@property() hass;
Expand Down Expand Up @@ -45,7 +46,7 @@ export class BaseLayout extends LitElement {
}
}

_shouldShow(card: LovelaceCard, config: CardConfig, index: number) {
_shouldShow(card: LovelaceCard | HuiCard, config: CardConfig, index: number) {
if (config.view_layout?.show === "always") return true;
if (config.view_layout?.show === "never") return false;
if (
Expand Down
5 changes: 3 additions & 2 deletions src/layouts/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { css, html } from "lit";
import {
CardConfig,
CardConfigGroup,
LovelaceCard,
GridViewConfig,
HuiCard,
LovelaceCard,
} from "../types";
import { BaseLayout } from "./base-layout";

Expand Down Expand Up @@ -90,7 +91,7 @@ class GridLayout extends BaseLayout {
}
}

_shouldShow(card: LovelaceCard, config: CardConfig, index: number) {
_shouldShow(card: LovelaceCard | HuiCard, config: CardConfig, index: number) {
if (!super._shouldShow(card, config, index)) return false;

const mq = this._mediaQueries[index];
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/horizontal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class HorizontalLayout extends BaseColumnLayout {
if (c.config.view_layout?.column) i = c.config.view_layout.column;
const col = cols[(i - 1) % cols.length];
col.appendChild(this.getCardElement(c));
if (this.isBreak(c.card)) {
if (this.isBreak(c.config)) {
i = 0;
if (!this.lovelace?.editMode) {
col.removeChild(c.card);
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/vertical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class VerticalLayout extends BaseColumnLayout {
if (c.config.view_layout?.column) i = c.config.view_layout.column;
const col = cols[(i - 1) % cols.length];
col.appendChild(this.getCardElement(c));
if (this.isBreak(c.card)) {
if (this.isBreak(c.config)) {
i = i + 1;
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ export interface LovelaceCard extends HTMLElement {
getCardSize?(): Promise<number> | number;
}

export interface HuiCard extends HTMLElement {
hass: any;
editMode?: boolean;
getCardSize?(): Promise<number> | number;
}

export interface CardConfig {
type: string;
view_layout?: {
Expand All @@ -20,7 +26,7 @@ export interface CardConfig {
}

export interface CardConfigGroup {
card: LovelaceCard;
card: LovelaceCard | HuiCard;
config: CardConfig;
index: number;
show?: boolean;
Expand Down