mirror of
https://github.com/home-assistant/frontend.git
synced 2026-02-04 01:10:33 -06:00
Merge favorite and common controls in home dashboard (#27438)
This commit is contained in:
parent
b679f1ce60
commit
3d27daad80
@ -16,7 +16,6 @@ import type {
|
||||
AreaCardConfig,
|
||||
HomeSummaryCard,
|
||||
MarkdownCardConfig,
|
||||
TileCardConfig,
|
||||
WeatherForecastCardConfig,
|
||||
} from "../../cards/types";
|
||||
import { getAreas, getFloors } from "../areas/helpers/areas-strategy-helper";
|
||||
@ -131,31 +130,14 @@ export class HomeMainViewStrategy extends ReactiveElement {
|
||||
const favoriteEntities = (config.favorite_entities || []).filter(
|
||||
(entityId) => hass.states[entityId] !== undefined
|
||||
);
|
||||
|
||||
if (favoriteEntities.length > 0) {
|
||||
favoriteSection.cards!.push(
|
||||
{
|
||||
type: "heading",
|
||||
heading: "",
|
||||
heading_style: "subtitle",
|
||||
},
|
||||
...favoriteEntities.map(
|
||||
(entityId) =>
|
||||
({
|
||||
type: "tile",
|
||||
entity: entityId,
|
||||
show_entity_picture: true,
|
||||
}) as TileCardConfig
|
||||
)
|
||||
);
|
||||
}
|
||||
const maxCommonControls = Math.max(8, favoriteEntities.length);
|
||||
|
||||
const commonControlsSection = {
|
||||
strategy: {
|
||||
type: "common-controls",
|
||||
title: hass.localize("ui.panel.lovelace.strategy.home.common_controls"),
|
||||
limit: 4,
|
||||
exclude_entities: favoriteEntities,
|
||||
limit: maxCommonControls,
|
||||
include_entities: favoriteEntities,
|
||||
hide_empty: true,
|
||||
} satisfies CommonControlSectionStrategyConfig,
|
||||
column_span: maxColumns,
|
||||
|
||||
@ -14,6 +14,7 @@ export interface CommonControlSectionStrategyConfig {
|
||||
icon?: string;
|
||||
limit?: number;
|
||||
exclude_entities?: string[];
|
||||
include_entities?: string[];
|
||||
hide_empty?: boolean;
|
||||
}
|
||||
|
||||
@ -52,12 +53,23 @@ export class CommonControlsSectionStrategy extends ReactiveElement {
|
||||
(entity) => entity in hass.states
|
||||
);
|
||||
|
||||
if (config.exclude_entities) {
|
||||
if (config.exclude_entities?.length) {
|
||||
predictedEntities = predictedEntities.filter(
|
||||
(entity) => !config.exclude_entities!.includes(entity)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.include_entities?.length) {
|
||||
// Remove included entities from predicted list to avoid duplicates
|
||||
predictedEntities = predictedEntities.filter(
|
||||
(entity) => !config.include_entities!.includes(entity)
|
||||
);
|
||||
// Add included entities to the start of the list
|
||||
predictedEntities.unshift(
|
||||
...config.include_entities!.filter((entity) => entity in hass.states)
|
||||
);
|
||||
}
|
||||
|
||||
const limit = config.limit ?? DEFAULT_LIMIT;
|
||||
predictedEntities = predictedEntities.slice(0, limit);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user