Skip to content

Commit

Permalink
Add capability to filter diagnostic entities
Browse files Browse the repository at this point in the history
  • Loading branch information
w531t4 committed Nov 9, 2024
1 parent 44a20b0 commit 71a5442
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/configurationDefaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const configurationDefaults: StrategyDefaults = {
domains: {
_: {
hide_config_entities: false,
hide_diagnostic_entities: false,
},
default: {
title: "Miscellaneous",
Expand Down
9 changes: 9 additions & 0 deletions src/mushroom-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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());
}

Expand Down
3 changes: 3 additions & 0 deletions src/types/strategy/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<cards.ControllerCardConfig> {
hidden?: boolean;
order?: number;
hide_config_entities?: boolean
hide_diagnostic_entities?: boolean
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/views/AbstractView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -105,6 +108,10 @@ abstract class AbstractView {
continue;
}

if (entity.entity_category === "diagnostic" && diagnosticEntityHidden) {
continue;
}

areaCards.push(new cardModule[className](entity, cardOptions).getCard());
}

Expand Down

0 comments on commit 71a5442

Please sign in to comment.