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 [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 --> <!-- Other References -->
[hacsUrl]: https://hacs.xyz [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 [mushroomUrl]: https://github.com/piitaya/lovelace-mushroom

2
package-lock.json generated
View File

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

View File

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

View File

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

View File

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

View File

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