Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to filter diagnostic entities #153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 19 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 All @@ -137,6 +141,11 @@ class MushroomStrategy extends HTMLTemplateElement {
const sensorCards: EntityCardConfig[] = [];

for (const sensor of entities) {
// Don't include the diagnostic-entity if hidden in the strategy options.
if (sensor.entity_category === "diagnostic" && diagnosticEntityHidden) {
continue;
}

// Find the state of the current sensor.
const sensorState = sensorStates.find(state => state.entity_id === sensor.entity_id);
let cardOptions = Helper.strategyOptions.card_options?.[sensor.entity_id];
Expand Down Expand Up @@ -188,6 +197,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 Expand Up @@ -267,6 +281,11 @@ class MushroomStrategy extends HTMLTemplateElement {
continue;
}

// Don't include the diagnostic-entity if hidden in the strategy options
if (entity.entity_category === "diagnostic" && Helper.strategyOptions.domains["_"].hide_diagnostic_entities) {
continue;
}

miscellaneousCards.push(new cardModule.MiscellaneousCard(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