Hide 'options' from enum more info (#26736)

* Hide 'options' from enum more info

* restrict to specific domain and class
This commit is contained in:
karwosts
2025-08-28 09:08:33 -07:00
committed by GitHub
parent e3a9d754df
commit cf8d36b1f3
2 changed files with 20 additions and 2 deletions

View File

@@ -3,11 +3,15 @@ import type { CSSResultGroup, PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display"; import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
import { STATE_ATTRIBUTES } from "../data/entity_attributes"; import {
STATE_ATTRIBUTES,
STATE_ATTRIBUTES_DOMAIN_CLASS,
} from "../data/entity_attributes";
import { haStyle } from "../resources/styles"; import { haStyle } from "../resources/styles";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
import "./ha-attribute-value"; import "./ha-attribute-value";
import "./ha-expansion-panel"; import "./ha-expansion-panel";
import { computeStateDomain } from "../common/entity/compute_state_domain";
@customElement("ha-attributes") @customElement("ha-attributes")
class HaAttributes extends LitElement { class HaAttributes extends LitElement {
@@ -22,7 +26,12 @@ class HaAttributes extends LitElement {
private get _filteredAttributes() { private get _filteredAttributes() {
return this._computeDisplayAttributes( return this._computeDisplayAttributes(
STATE_ATTRIBUTES.concat( STATE_ATTRIBUTES.concat(
this.extraFilters ? this.extraFilters.split(",") : [] this.extraFilters ? this.extraFilters.split(",") : [],
(this.stateObj &&
STATE_ATTRIBUTES_DOMAIN_CLASS[computeStateDomain(this.stateObj)]?.[
this.stateObj.attributes?.device_class
]) ||
[]
) )
); );
} }

View File

@@ -1,6 +1,7 @@
import { formatDurationDigital } from "../common/datetime/format_duration"; import { formatDurationDigital } from "../common/datetime/format_duration";
import type { FrontendLocaleData } from "./translation"; import type { FrontendLocaleData } from "./translation";
// These attributes are hidden from the more-info window for all entities.
export const STATE_ATTRIBUTES = [ export const STATE_ATTRIBUTES = [
"entity_id", "entity_id",
"assumed_state", "assumed_state",
@@ -26,6 +27,14 @@ export const STATE_ATTRIBUTES = [
"available_tones", "available_tones",
]; ];
// These attributes are hidden from the more-info window for entities of the
// matching domain and device_class.
export const STATE_ATTRIBUTES_DOMAIN_CLASS = {
sensor: {
enum: ["options"],
},
};
export const TEMPERATURE_ATTRIBUTES = new Set([ export const TEMPERATURE_ATTRIBUTES = new Set([
"temperature", "temperature",
"current_temperature", "current_temperature",