Add option to hide config-entities (#103).

* Introduces a `hide_config_entities` strategy-option to define if a 
  config-entity should be hidden or not.

* Bumps version number to 2.1.0

---------

Co-authored-by: DigiLive <github@digilive.nl>
This commit is contained in:
Subhash Chandra
2024-02-01 11:27:39 +05:30
committed by GitHub
parent 2970be7ff3
commit fba9364106
7 changed files with 41 additions and 9 deletions

View File

@ -67,13 +67,13 @@ Visit the [issues](https://github.com/AalianKhan/mushroom-strategy/issues/new/ch
[sponsorBadge]: https://img.shields.io/badge/Sponsor_him-%E2%9D%A4-%23db61a2.svg?&logo=github&color=%23fe8e86
[releaseBadge]: https://img.shields.io/badge/Release-v2.0.3-blue
[releaseBadge]: https://img.shields.io/badge/Release-v2.1.0-blue
<!-- Other References -->
[hacsUrl]: https://hacs.xyz
[releaseUrl]: https://github.com/AalianKhan/mushroom-strategy/releases/tag/v2.0.3
[releaseUrl]: https://github.com/AalianKhan/mushroom-strategy/releases/tag/v2.1.0
[mushroomUrl]: https://github.com/piitaya/lovelace-mushroom

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "mushroom-strategy",
"version": "2.0.3",
"version": "2.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {

View File

@ -1,6 +1,6 @@
{
"name": "mushroom-strategy",
"version": "2.0.3",
"version": "2.1.0",
"description": "Automatically create a dashboard using Mushroom cards",
"keywords": [
"strategy",

View File

@ -16,6 +16,9 @@ export const configurationDefaults: StrategyDefaults = {
},
debug: false,
domains: {
_: {
hide_config_entities: false,
},
default: {
title: "Miscellaneous",
showControls: false,

View File

@ -113,6 +113,9 @@ class MushroomStrategy extends HTMLTemplateElement {
domainCards = await import(`./cards/${className}`).then(cardModule => {
let domainCards = [];
const entities = Helper.getDeviceEntities(area, domain);
let configEntityHidden =
Helper.strategyOptions.domains[domain ?? "_"].hide_config_entities
|| Helper.strategyOptions.domains["_"].hide_config_entities;
// Set the target for controller cards to entities without an area.
if (area.area_id === "undisclosed") {
@ -175,9 +178,17 @@ class MushroomStrategy extends HTMLTemplateElement {
deviceOptions = Helper.strategyOptions.card_options?.[entity.device_id];
}
if (!cardOptions?.hidden && !deviceOptions?.hidden) {
domainCards.push(new cardModule[className](entity, cardOptions).getCard());
// Don't include the entity if hidden in the strategy options.
if (cardOptions?.hidden || deviceOptions?.hidden) {
continue;
}
// Don't include the config-entity if hidden in the strategy options.
if (entity.entity_category === "config" && configEntityHidden) {
continue;
}
domainCards.push(new cardModule[className](entity, cardOptions).getCard());
}
if (domain === "binary_sensor") {
@ -246,9 +257,17 @@ class MushroomStrategy extends HTMLTemplateElement {
let cardOptions = Helper.strategyOptions.card_options?.[entity.entity_id];
let deviceOptions = Helper.strategyOptions.card_options?.[entity.device_id ?? "null"];
if (!cardOptions?.hidden && !deviceOptions?.hidden) {
miscellaneousCards.push(new cardModule.MiscellaneousCard(entity, cardOptions).getCard());
// Don't include the entity if hidden in the strategy options.
if (cardOptions?.hidden || deviceOptions?.hidden) {
continue;
}
// Don't include the config-entity if hidden in the strategy options
if (entity.entity_category === "config" && Helper.strategyOptions.domains["_"].hide_config_entities) {
continue;
}
miscellaneousCards.push(new cardModule.MiscellaneousCard(entity, cardOptions).getCard());
}
return miscellaneousCards;
@ -273,7 +292,7 @@ class MushroomStrategy extends HTMLTemplateElement {
customElements.define("ll-strategy-mushroom-strategy", MushroomStrategy);
const version = "v2.0.3";
const version = "v2.1.0";
console.info(
"%c Mushroom Strategy %c ".concat(version, " "),
"color: white; background: coral; font-weight: 700;", "color: coral; background: white; font-weight: 700;"

View File

@ -36,10 +36,13 @@ export namespace generic {
*
* @property {number} [order] Ordering position of the entity in the list of available views.
* @property {boolean} [hidden] True if the entity should be hidden from the dashboard.
* @property {boolean} [hide_config_entities] True if the entity's categorie is "config" and should be hidden from the
* dashboard.
*/
export interface DomainConfig extends Partial<cards.ControllerCardConfig> {
hidden?: boolean;
order?: number;
hide_config_entities?: boolean
}
/**

View File

@ -69,6 +69,9 @@ abstract class AbstractView {
*/
async createViewCards(): Promise<(StackCardConfig | TitleCardConfig)[]> {
const viewCards: LovelaceCardConfig[] = [];
const configEntityHidden =
Helper.strategyOptions.domains[this.#domain ?? "_"].hide_config_entities
|| Helper.strategyOptions.domains["_"].hide_config_entities;
// Create cards for each area.
for (const area of Helper.areas) {
@ -98,6 +101,10 @@ abstract class AbstractView {
continue;
}
if (entity.entity_category === "config" && configEntityHidden) {
continue;
}
areaCards.push(new cardModule[className](entity, cardOptions).getCard());
}