Add capability to filter diagnostic entities

This commit is contained in:
Aaron White
2024-11-09 13:55:49 -05:00
committed by 0xFEEDC0DE64
parent 0c2649e08e
commit 51eed209fc
4 changed files with 30 additions and 0 deletions

View File

@ -22,6 +22,7 @@ export const getConfigurationDefaults = (localize: Function): StrategyDefaults =
domains: {
_: {
hide_config_entities: false,
hide_diagnostic_entities: false,
},
default: {
title: localize("generic.miscellaneous"),

View File

@ -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 = {
@ -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];
@ -180,6 +189,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());
}
@ -242,6 +256,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());
}

View File

@ -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
}
/**

View File

@ -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());
}