Skip to content

Commit

Permalink
fix: fix area with no floor_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Lebe1ge committed Dec 12, 2024
1 parent f23f63e commit 97fc2d2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class Helper {
if (!(entity.entity_id in this.#hassStates) || entity.hidden_by) return acc;

const area = entity.area_id ? areasById[entity.area_id] : {} as StrategyArea;
const floor = area.floor_id ? floorsById[area.floor_id] : {} as StrategyFloor;
const floor = area?.floor_id ? floorsById[area?.floor_id] : {} as StrategyFloor;
const enrichedEntity = {
...entity,
floor_id: floor.floor_id || null,
Expand Down Expand Up @@ -359,7 +359,7 @@ class Helper {
this.#devices = devices.reduce((acc, device) => {
const entitiesInDevice = entitiesByDeviceId[device.id] || [];
const area = device.area_id ? areasById[device.area_id] : {} as StrategyArea;
const floor = area.floor_id ? floorsById[area.floor_id] : {} as StrategyFloor;
const floor = area?.floor_id ? floorsById[area?.floor_id] : {} as StrategyFloor;

const enrichedDevice = {
...device,
Expand Down Expand Up @@ -411,7 +411,7 @@ class Helper {

const enrichedArea = {
...area,
floor_id: area.floor_id || UNDISCLOSED,
floor_id: area?.floor_id || UNDISCLOSED,
slug,
domains: groupEntitiesByDomain(areaEntities) ?? {},
devices: devicesByAreaId[area.area_id]?.map(device => device.id) || [],
Expand All @@ -437,7 +437,7 @@ class Helper {

// Enrichir les étages
this.#floors = floors.reduce((acc, floor) => {
const areasInFloor = Object.values(this.#areas).filter(area => area.floor_id === floor.floor_id);
const areasInFloor = Object.values(this.#areas).filter(area => area?.floor_id === floor.floor_id);

acc[floor.floor_id] = {
...floor,
Expand Down
7 changes: 1 addition & 6 deletions src/chips/ConditionalChip.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { chips } from "../types/strategy/chips";
import { ConditionalChipConfig, LovelaceChipConfig } from "../types/lovelace-mushroom/utils/lovelace/chip/types";
import { getMAEntity } from "../utils";
import { generic } from "../types/strategy/generic";
import MagicAreaRegistryEntry = generic.MagicAreaRegistryEntry;
import { AbstractChip } from "./AbstractChip";

type ConditionalChipOptions = Omit<ConditionalChipConfig, "type">
Expand Down Expand Up @@ -32,13 +28,12 @@ class ConditionalChip extends AbstractChip {
* @param {MagicAreaRegistryEntry} device The chip device.
* @param {ConditionalChipOptions} options The chip options.
*/
constructor(conditions: [{ entity: string; state_not: string; } | { entity: string; state: string; }], chip: LovelaceChipConfig) {
constructor(conditions: Array<{ entity: string; state_not?: string; state?: string; }>, chip: LovelaceChipConfig) {
super();

this.#defaultConfig.conditions = conditions;
this.#defaultConfig.chip = chip;


this.config = Object.assign(this.config, this.#defaultConfig);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/popups/SettingsPopup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class SettingsPopup extends AbstractPopup {
content: {
type: "vertical-stack",
cards: [
linusDeviceIds.length > 0 && {
{
type: "horizontal-stack",
cards: [
{
linusDeviceIds.length > 0 && {
type: "custom:mushroom-template-card",
primary: Helper.localize("component.linus_dashboard.entity.button.settings_chip.state.on"),
icon: "mdi:refresh",
Expand All @@ -48,13 +48,13 @@ class SettingsPopup extends AbstractPopup {
service: "homeassistant.restart",
}
},
]
].filter(Boolean)
},
{
type: "markdown",
content: `Linus dashboard est en version ${version}.`,
},
].filter(Boolean)
]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/lovelace-mushroom/utils/lovelace/chip/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export type TemplateChipConfig = {
export interface ConditionalChipConfig {
type: "conditional";
chip?: LovelaceChipConfig;
conditions?: [{ entity: string; state_not: string } | { entity: string; state: string }];
conditions?: Array<{ entity: string; state_not?: string; state?: string; }>
}

/**
Expand Down

0 comments on commit 97fc2d2

Please sign in to comment.