Skip to content

Commit

Permalink
fix: remove floor controller when no floors and fix unavailable chips
Browse files Browse the repository at this point in the history
  • Loading branch information
Lebe1ge committed Dec 9, 2024
1 parent 3347f18 commit 9fe3d49
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 43 deletions.
3 changes: 0 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 5 additions & 3 deletions src/views/AbstractView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 1 addition & 13 deletions src/views/AggregateView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/views/AreaView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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",
Expand Down
54 changes: 30 additions & 24 deletions src/views/HomeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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 = {
Expand All @@ -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()) {

Expand Down

0 comments on commit 9fe3d49

Please sign in to comment.