Improve device info add to Lovelace (#10413)

This commit is contained in:
Paulus Schoutsen 2021-10-26 12:03:19 -07:00 committed by GitHub
parent 0b2404a0f2
commit e50d2e16a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 14 deletions

View File

@ -187,7 +187,8 @@ export class HaDeviceEntitiesCard extends LitElement {
this.hass,
this.entities
.filter((entity) => !entity.disabled_by)
.map((entity) => entity.entity_id)
.map((entity) => entity.entity_id),
this.deviceName
);
}

View File

@ -20,7 +20,6 @@ import {
AlarmPanelCardConfig,
EntitiesCardConfig,
HumidifierCardConfig,
LightCardConfig,
PictureEntityCardConfig,
ThermostatCardConfig,
} from "../cards/types";
@ -84,8 +83,7 @@ const splitByAreas = (
export const computeCards = (
states: Array<[string, HassEntity?]>,
entityCardOptions: Partial<EntitiesCardConfig>,
single = false
entityCardOptions: Partial<EntitiesCardConfig>
): LovelaceCardConfig[] => {
const cards: LovelaceCardConfig[] = [];
@ -123,12 +121,6 @@ export const computeCards = (
entity: entityId,
};
cards.push(cardConfig);
} else if (domain === "light" && single) {
const cardConfig: LightCardConfig = {
type: "light",
entity: entityId,
};
cards.push(cardConfig);
} else if (domain === "media_player") {
const cardConfig = {
type: "media-control",

View File

@ -13,8 +13,10 @@ import { showSelectViewDialog } from "./select-view/show-select-view-dialog";
export const addEntitiesToLovelaceView = async (
element: HTMLElement,
hass: HomeAssistant,
entities: string[]
entities: string[],
cardTitle?: string
) => {
hass.loadFragmentTranslation("lovelace");
const dashboards = await fetchDashboards(hass);
const storageDashs = dashboards.filter(
@ -30,6 +32,7 @@ export const addEntitiesToLovelaceView = async (
showSuggestCardDialog(element, {
entities,
yaml: true,
cardTitle,
});
return;
}
@ -68,6 +71,7 @@ export const addEntitiesToLovelaceView = async (
showSuggestCardDialog(element, {
entities,
yaml: true,
cardTitle,
});
} else {
// all storage dashboards are generated
@ -87,6 +91,7 @@ export const addEntitiesToLovelaceView = async (
if (!storageDashs.length && lovelaceConfig.views.length === 1) {
showSuggestCardDialog(element, {
cardTitle,
lovelaceConfig: lovelaceConfig!,
saveConfig: async (newConfig: LovelaceConfig): Promise<void> => {
try {
@ -107,9 +112,11 @@ export const addEntitiesToLovelaceView = async (
lovelaceConfig,
urlPath,
allowDashboardChange: true,
actionLabel: hass.localize("ui.common.next"),
dashboards,
viewSelectedCallback: (newUrlPath, selectedDashConfig, viewIndex) => {
showSuggestCardDialog(element, {
cardTitle,
lovelaceConfig: selectedDashConfig,
saveConfig: async (newConfig: LovelaceConfig): Promise<void> => {
try {

View File

@ -35,8 +35,9 @@ export class HuiDialogSuggestCard extends LitElement {
entityId,
this.hass.states[entityId],
]),
{},
true
{
title: params.cardTitle,
}
);
if (!Object.isFrozen(this._cardConfig)) {
this._cardConfig = deepFreeze(this._cardConfig);

View File

@ -2,6 +2,7 @@ import { fireEvent } from "../../../../common/dom/fire_event";
import { LovelaceCardConfig, LovelaceConfig } from "../../../../data/lovelace";
export interface SuggestCardDialogParams {
cardTitle?: string;
lovelaceConfig?: LovelaceConfig;
yaml?: boolean;
saveConfig?: (config: LovelaceConfig) => void;

View File

@ -131,7 +131,7 @@ export class HuiDialogSelectView extends LitElement {
${this.hass!.localize("ui.common.cancel")}
</mwc-button>
<mwc-button slot="primaryAction" @click=${this._selectView}>
${this.hass!.localize("ui.common.move")}
${this._params.actionLabel || this.hass!.localize("ui.common.move")}
</mwc-button>
</ha-dialog>
`;

View File

@ -7,6 +7,7 @@ export interface SelectViewDialogParams {
dashboards?: LovelaceDashboard[];
urlPath?: string | null;
header?: string;
actionLabel?: string;
viewSelectedCallback: (
urlPath: string | null,
config: LovelaceConfig,