Skip to content

Add option to show icons for areas dashboard strategy #25627

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
order?: string[];
};
areas_options?: Record<string, AreaOptions>;
show_icons?: boolean;
}

@customElement("areas-dashboard-strategy")
Expand Down Expand Up @@ -59,12 +60,13 @@
config.areas_display?.order
);

const areaViews = areas.map<LovelaceViewRawConfig>((area) => {

Check failure on line 63 in src/panels/lovelace/strategies/areas/areas-dashboard-strategy.ts

View workflow job for this annotation

GitHub Actions / Lint and check format

Argument of type '(area: AreaRegistryEntry) => { title: string; icon: string | null | undefined; path: string; strategy: { type: "area"; area: string; groups_options: Record<string, EntitiesDisplay> | undefined; }; }' is not assignable to parameter of type '(value: AreaRegistryEntry, index: number, array: AreaRegistryEntry[]) => LovelaceViewRawConfig'.
const path = computeAreaPath(area.area_id);
const areaConfig = config.areas_options?.[area.area_id];

return {
title: area.name,
icon: config.show_icons ? area.icon : undefined,
path: path,
strategy: {
type: "area",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ import {
type AreaRegistryEntry,
} from "../../../../../data/area_registry";
import { buttonLinkStyle } from "../../../../../resources/styles";
import type {
HaFormSchema,
SchemaUnion,
} from "../../../../../components/ha-form/types";

const SCHEMA = [
{
name: "show_icons",
selector: {
boolean: {},
},
},
] as const satisfies readonly HaFormSchema[];

@customElement("hui-areas-dashboard-strategy-editor")
export class HuiAreasDashboardStrategyEditor
Expand Down Expand Up @@ -133,6 +146,13 @@ export class HuiAreasDashboardStrategyEditor
show-navigation-button
@item-display-navigate-clicked=${this._handleAreaNavigate}
></ha-areas-display-editor>
<ha-form
.hass=${this.hass}
.data=${this._config}
.schema=${SCHEMA}
.computeLabel=${this._computeFormLabelCallback}
@value-changed=${this._formValueChanged}
></ha-form>
`;
}

Expand Down Expand Up @@ -186,11 +206,28 @@ export class HuiAreasDashboardStrategyEditor
},
},
},
show_icons: this._config!.show_icons,
};

fireEvent(this, "config-changed", { config: newConfig });
}

private _formValueChanged(ev: CustomEvent): void {
const data = ev.detail.value;
fireEvent(this, "config-changed", { config: data });
}

private _computeFormLabelCallback = (schema: SchemaUnion<typeof SCHEMA>) => {
switch (schema.name) {
case "show_icons":
return this.hass?.localize(
`ui.panel.lovelace.editor.strategy.areas.show_icons`
);
default:
return "";
}
};

static get styles() {
return [
buttonLinkStyle,
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7836,7 +7836,8 @@
},
"areas": {
"areas_display": "Areas to display",
"no_entities": "No entities in this group, the section will not be displayed"
"no_entities": "No entities in this group, the section will not be displayed",
"show_icons": "Show assigned area icons on the dashboard tabs"
}
},
"view": {
Expand Down
Loading