From 71a544241bd5b2870e1d9b653fad37c3b4c5fcb3 Mon Sep 17 00:00:00 2001 From: Aaron White Date: Sat, 9 Nov 2024 13:55:49 -0500 Subject: [PATCH] Add capability to filter diagnostic entities --- src/configurationDefaults.ts | 1 + src/mushroom-strategy.ts | 9 +++++++++ src/types/strategy/generic.ts | 3 +++ src/views/AbstractView.ts | 7 +++++++ 4 files changed, 20 insertions(+) diff --git a/src/configurationDefaults.ts b/src/configurationDefaults.ts index c777041..540a4d2 100644 --- a/src/configurationDefaults.ts +++ b/src/configurationDefaults.ts @@ -18,6 +18,7 @@ export const configurationDefaults: StrategyDefaults = { domains: { _: { hide_config_entities: false, + hide_diagnostic_entities: false, }, default: { title: "Miscellaneous", diff --git a/src/mushroom-strategy.ts b/src/mushroom-strategy.ts index 21af6c0..52a2cd6 100644 --- a/src/mushroom-strategy.ts +++ b/src/mushroom-strategy.ts @@ -117,6 +117,10 @@ class MushroomStrategy extends HTMLTemplateElement { Helper.strategyOptions.domains[domain ?? "_"].hide_config_entities || Helper.strategyOptions.domains["_"].hide_config_entities; + let diagnosticEntityHidden = + Helper.strategyOptions.domains[domain ?? "_"].hide_diagnostic_entities + || Helper.strategyOptions.domains["_"].hide_diagnostic_entities; + // Set the target for controller cards to entities without an area. if (area.area_id === "undisclosed") { target = { @@ -188,6 +192,11 @@ class MushroomStrategy extends HTMLTemplateElement { continue; } + // Don't include the diagnostic-entity if hidden in the strategy options. + if (entity.entity_category === "diagnostic" && diagnosticEntityHidden) { + continue; + } + domainCards.push(new cardModule[className](entity, cardOptions).getCard()); } diff --git a/src/types/strategy/generic.ts b/src/types/strategy/generic.ts index 821d5fc..3ed4946 100644 --- a/src/types/strategy/generic.ts +++ b/src/types/strategy/generic.ts @@ -38,11 +38,14 @@ export namespace generic { * @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. + * @property {boolean} [hide_diagnostic_entities] True if the entity's categorie is "diagnostic" and should be hidden from the + * dashboard. */ export interface DomainConfig extends Partial { hidden?: boolean; order?: number; hide_config_entities?: boolean + hide_diagnostic_entities?: boolean } /** diff --git a/src/views/AbstractView.ts b/src/views/AbstractView.ts index 497cdaa..60d75f6 100644 --- a/src/views/AbstractView.ts +++ b/src/views/AbstractView.ts @@ -72,6 +72,9 @@ abstract class AbstractView { const configEntityHidden = Helper.strategyOptions.domains[this.#domain ?? "_"].hide_config_entities || Helper.strategyOptions.domains["_"].hide_config_entities; + const diagnosticEntityHidden = + Helper.strategyOptions.domains[this.#domain ?? "_"].hide_diagnostic_entities + || Helper.strategyOptions.domains["_"].hide_diagnostic_entities; // Create cards for each area. for (const area of Helper.areas) { @@ -105,6 +108,10 @@ abstract class AbstractView { continue; } + if (entity.entity_category === "diagnostic" && diagnosticEntityHidden) { + continue; + } + areaCards.push(new cardModule[className](entity, cardOptions).getCard()); }