Merge pull request #47 from AalianKhan/hide-default-domain

Fix hiding default domain
This commit is contained in:
Aalian Khan
2023-09-12 07:34:31 -04:00
committed by GitHub
2 changed files with 48 additions and 46 deletions

File diff suppressed because one or more lines are too long

View File

@@ -188,52 +188,54 @@ class MushroomStrategy {
}
}
// TODO: Check if default is hidden
// Create cards for any other domain.
// Collect device entities of the current area.
const areaDevices = Helper.devices.filter(device => device.area_id === area.area_id)
.map(device => device.id);
// Collect the remaining entities of which all conditions below are met:
// 1. The entity is linked to a device which is linked to the current area,
// or the entity itself is linked to the current area.
// 2. The entity is not hidden and is not disabled.
const miscellaneousEntities = Helper.entities.filter(entity => {
return (areaDevices.includes(entity.device_id) || entity.area_id === area.area_id)
&& entity.hidden_by == null
&& entity.disabled_by == null
&& !exposedDomainIds.includes(entity.entity_id.split(".", 1)[0]);
});
// Create a column of miscellaneous entity cards.
if (miscellaneousEntities.length) {
let miscellaneousCards = [];
try {
miscellaneousCards = await import("./cards/MiscellaneousCard").then(cardModule => {
/** @type Object[] */
const miscellaneousCards = [
new TitleCard([area], Helper.strategyOptions.domains.default).createCard(),
];
for (const entity of miscellaneousEntities) {
let cardOptions = Helper.strategyOptions.card_options?.[entity.entity_id] ?? {};
if (!cardOptions.hidden) {
miscellaneousCards.push(new cardModule.MiscellaneousCard(entity, cardOptions).getCard());
}
}
return miscellaneousCards;
});
} catch (e) {
console.error(Helper.debug ? e : "An error occurred while creating the domain cards!");
}
viewCards.push({
type: "vertical-stack",
cards: miscellaneousCards,
if (!Helper.strategyOptions.domains.default.hidden) {
// TODO: Check if default is hidden
// Create cards for any other domain.
// Collect device entities of the current area.
const areaDevices = Helper.devices.filter(device => device.area_id === area.area_id)
.map(device => device.id);
// Collect the remaining entities of which all conditions below are met:
// 1. The entity is linked to a device which is linked to the current area,
// or the entity itself is linked to the current area.
// 2. The entity is not hidden and is not disabled.
const miscellaneousEntities = Helper.entities.filter(entity => {
return (areaDevices.includes(entity.device_id) || entity.area_id === area.area_id)
&& entity.hidden_by == null
&& entity.disabled_by == null
&& !exposedDomainIds.includes(entity.entity_id.split(".", 1)[0]);
});
// Create a column of miscellaneous entity cards.
if (miscellaneousEntities.length) {
let miscellaneousCards = [];
try {
miscellaneousCards = await import("./cards/MiscellaneousCard").then(cardModule => {
/** @type Object[] */
const miscellaneousCards = [
new TitleCard([area], Helper.strategyOptions.domains.default).createCard(),
];
for (const entity of miscellaneousEntities) {
let cardOptions = Helper.strategyOptions.card_options?.[entity.entity_id] ?? {};
if (!cardOptions.hidden) {
miscellaneousCards.push(new cardModule.MiscellaneousCard(entity, cardOptions).getCard());
}
}
return miscellaneousCards;
});
} catch (e) {
console.error(Helper.debug ? e : "An error occurred while creating the domain cards!");
}
viewCards.push({
type: "vertical-stack",
cards: miscellaneousCards,
});
}
}
// Return cards.