diff --git a/src/utils.ts b/src/utils.ts index 1e0d418..c8d1755 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -146,9 +146,6 @@ export async function createChipsFromList(chipsList: string[], chipOptions?: Par } } - const unavailableChip = new UnavailableChip({ area_slug }).getChip(); - if (unavailableChip) chips.push(unavailableChip); - return chips; } diff --git a/src/views/AbstractView.ts b/src/views/AbstractView.ts index 4fbdbd5..f5e92c3 100644 --- a/src/views/AbstractView.ts +++ b/src/views/AbstractView.ts @@ -103,7 +103,9 @@ abstract class AbstractView { || Helper.strategyOptions.domains["_"].hide_config_entities; let isFirstLoop = true; - for (const floor of Helper.orderedFloors) { + const floors = Helper.orderedFloors; + + for (const floor of floors) { if (floor.areas_slug.length === 0 || !AREA_CARDS_DOMAINS.includes(this.#domain ?? "")) continue; const floorCards = []; @@ -162,12 +164,12 @@ abstract class AbstractView { } const area_ids = floor.areas_slug.map(area_slug => Helper.areas[area_slug].area_id); - const floorControllerCard = new ControllerCard( + const floorControllerCard = floors.length > 1 ? new ControllerCard( { area_id: area_ids }, titleSectionOptions, this.#domain, floor.floor_id - ).createCard(); + ).createCard() : []; const section = { type: "grid", cards: [] } as LovelaceGridCardConfig; if (isFirstLoop) { diff --git a/src/views/AggregateView.ts b/src/views/AggregateView.ts index 7e94e41..6e66ff6 100644 --- a/src/views/AggregateView.ts +++ b/src/views/AggregateView.ts @@ -16,18 +16,6 @@ import { getDomainTranslationKey } from "../utils"; */ class AggregateView extends AbstractView { - /** - * Default configuration of the view. - * - * @type {views.ViewConfig} - * @private - */ - #defaultConfig: views.ViewConfig = { - title: "Aggregates", - icon: "mdi:fan", - subview: true, - }; - /** * Class constructor. * @@ -41,7 +29,7 @@ class AggregateView extends AbstractView { this.viewControllerCard = new ControllerCard( this.targetDomain(options?.device_class), { - title: `${Helper.localize(getDomainTranslationKey(domain, options?.device_class))}s`, + title: Helper.localize(getDomainTranslationKey(domain, options?.device_class)), // subtitle: Helper.getDeviceClassCountTemplate(options?.device_class, "eq", "on") + ` ${Helper.localize(getStateTranslationKey("on", domain, options?.device_class))}s`, controlChipOptions: { device_class: options?.device_class }, }, domain, "global").createCard(); diff --git a/src/views/AreaView.ts b/src/views/AreaView.ts index dfac691..68568f8 100644 --- a/src/views/AreaView.ts +++ b/src/views/AreaView.ts @@ -16,6 +16,7 @@ import { LovelaceChipConfig } from "../types/lovelace-mushroom/utils/lovelace/ch import { AreaStateChip } from "../chips/AreaStateChip"; import { createChipsFromList, getDomainTranslationKey } from "../utils"; import { ResourceKeys } from "../types/homeassistant/data/frontend"; +import { UnavailableChip } from "../chips/UnavailableChip"; // noinspection JSUnusedGlobalSymbols Class is dynamically imported. @@ -88,6 +89,9 @@ class AreaView { chips.push(...areaChips); } + const unavailableChip = new UnavailableChip({ area_slug: this.area.slug }).getChip(); + if (unavailableChip) chips.push(unavailableChip); + // (device?.entities.all_lights && device?.entities.all_lights.entity_id !== "unavailable" ? { // type: "custom:mushroom-chips-card", // alignment: "center", diff --git a/src/views/HomeView.ts b/src/views/HomeView.ts index ba8b1b4..d29b17f 100644 --- a/src/views/HomeView.ts +++ b/src/views/HomeView.ts @@ -15,6 +15,7 @@ import { WeatherChip } from "../chips/WeatherChip"; import { AggregateChip } from "../chips/AggregateChip"; import { PersonCard } from "../cards/PersonCard"; import { ConditionalChip } from "../chips/ConditionalChip"; +import { UnavailableChip } from "../chips/UnavailableChip"; // noinspection JSUnusedGlobalSymbols Class is dynamically imported. @@ -117,6 +118,9 @@ class HomeView { chips.push(...homeChips); } + const unavailableChip = new UnavailableChip().getChip(); + if (unavailableChip) chips.push(unavailableChip); + const linusSettings = new SettingsChip({ tap_action: new SettingsPopup().getPopup() }) chips.push(linusSettings.getChip()); @@ -240,9 +244,10 @@ class HomeView { } const groupedSections: LovelaceGridCardConfig[] = []; + const floors = Helper.orderedFloors let isFirstLoop = true; - for (const floor of Helper.orderedFloors) { + for (const floor of floors) { if (floor.areas_slug.length === 0) continue let floorSection = { @@ -263,33 +268,34 @@ class HomeView { const temperatureEntity = getMAEntity(floor.floor_id, "sensor", "temperature"); - - floorSection.cards.push( - { - type: "heading", - heading: getFloorName(floor), - heading_style: "subtitle", - icon: floor.icon ?? "mdi:floor-plan", - badges: [{ - type: "custom:mushroom-chips-card", - alignment: "end", - chips: [ - new ConditionalChip( - [{ entity: temperatureEntity?.entity_id!, state_not: UNAVAILABLE }], - new AggregateChip({ device_class: "temperature", show_content: true, magic_device_id: floor.floor_id, area_slug: floor.areas_slug }).getChip() - ).getChip(), - ], - card_mod: { - style: ` + if (floors.length > 1) { + floorSection.cards.push( + { + type: "heading", + heading: getFloorName(floor), + heading_style: "subtitle", + icon: floor.icon ?? "mdi:floor-plan", + badges: [{ + type: "custom:mushroom-chips-card", + alignment: "end", + chips: [ + new ConditionalChip( + [{ entity: temperatureEntity?.entity_id!, state_not: UNAVAILABLE }], + new AggregateChip({ device_class: "temperature", show_content: true, magic_device_id: floor.floor_id, area_slug: floor.areas_slug }).getChip() + ).getChip(), + ], + card_mod: { + style: ` ha-card { min-width: 80px; } `, - } - }], - tap_action: floor.floor_id !== UNDISCLOSED ? navigateTo(slugify(floor.name)) : undefined, - } - ); + } + }], + tap_action: floor.floor_id !== UNDISCLOSED ? navigateTo(slugify(floor.name)) : undefined, + } + ); + } for (const area of floor.areas_slug.map(area_slug => Helper.areas[area_slug]).values()) {