Skip to content

Commit

Permalink
Fix suggest card dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya committed Feb 8, 2024
1 parent c3b2ebf commit c490e17
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import "./hui-entity-picker-table";
import { CreateCardDialogParams } from "./show-create-card-dialog";
import { showEditCardDialog } from "./show-edit-card-dialog";
import { showSuggestCardDialog } from "./show-suggest-card-dialog";
import { computeCards } from "../../common/generate-lovelace-config";

declare global {
interface HASSDomEvents {
Expand Down Expand Up @@ -242,11 +243,17 @@ export class HuiCreateDialogCard
}

private _suggestCards(): void {
const cardConfig = computeCards(
this.hass.states,
this._selectedEntities,
{}
);
showSuggestCardDialog(this, {
lovelaceConfig: this._params!.lovelaceConfig,
saveConfig: this._params!.saveConfig,
path: this._params!.path as [number],
entities: this._selectedEntities,
cardConfig,
});

this.closeDialog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ export interface SuggestCardDialogParams {
yaml?: boolean;
saveConfig?: (config: LovelaceConfig) => void;
path?: [number];
entities?: string[]; // Entities used to generate the card config. We pass this to create dialog when user chooses "Pick own"
cardConfig?: LovelaceCardConfig[]; // We can pass a suggested config
entities?: string[]; // We pass this to create dialog when user chooses "Pick own"
cardConfig: LovelaceCardConfig[]; // We can pass a suggested config
}

const importsuggestCardDialog = () => import("./hui-dialog-suggest-card");
const importSuggestCardDialog = () => import("./hui-dialog-suggest-card");

export const showSuggestCardDialog = (
element: HTMLElement,
suggestCardDialogParams: SuggestCardDialogParams
): void => {
fireEvent(element, "show-dialog", {
dialogTag: "hui-dialog-suggest-card",
dialogImport: importsuggestCardDialog,
dialogImport: importSuggestCardDialog,
dialogParams: suggestCardDialogParams,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import "../card-editor/hui-entity-picker-table";
import { showSuggestCardDialog } from "../card-editor/show-suggest-card-dialog";
import { showSelectViewDialog } from "../select-view/show-select-view-dialog";
import { LovelaceConfig } from "../../../../data/lovelace/config/types";
import { computeCards } from "../../common/generate-lovelace-config";

@customElement("hui-unused-entities")
export class HuiUnusedEntities extends LitElement {
Expand Down Expand Up @@ -126,12 +127,18 @@ export class HuiUnusedEntities extends LitElement {
}

private _addToLovelaceView(): void {
const cardConfig = computeCards(
this.hass.states,
this._selectedEntities,
{}
);
if (this.lovelace.config.views.length === 1) {
showSuggestCardDialog(this, {
lovelaceConfig: this.lovelace.config!,
saveConfig: this.lovelace.saveConfig,
path: [0],
entities: this._selectedEntities,
cardConfig,
});
return;
}
Expand All @@ -144,6 +151,7 @@ export class HuiUnusedEntities extends LitElement {
saveConfig: this.lovelace.saveConfig,
path: [viewIndex],
entities: this._selectedEntities,
cardConfig,
});
},
});
Expand Down

0 comments on commit c490e17

Please sign in to comment.