From 9c153bbd58d7d8cb228125516a2448203fc91ed5 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 18 Jun 2024 02:58:45 -0400 Subject: [PATCH] Split out service entities (#21076) * Hide notify entiites from generated dashboard * Split out service entities on device info page * Update src/panels/lovelace/common/generate-lovelace-config.ts * Split service -> notify/assist --- src/common/const.ts | 5 +- .../config/devices/ha-config-device-page.ts | 46 ++++++++++++++----- .../common/generate-lovelace-config.ts | 6 +-- src/translations/en.json | 2 + 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/src/common/const.ts b/src/common/const.ts index 3bbada135924..4f5c4af426fd 100644 --- a/src/common/const.ts +++ b/src/common/const.ts @@ -31,6 +31,7 @@ import { mdiFormatListBulleted, mdiFormatListCheckbox, mdiFormTextbox, + mdiForumOutline, mdiGauge, mdiGoogleAssistant, mdiGoogleCirclesCommunities, @@ -98,7 +99,7 @@ export const FIXED_DOMAIN_ICONS = { calendar: mdiCalendar, climate: mdiThermostat, configurator: mdiCog, - conversation: mdiMicrophoneMessage, + conversation: mdiForumOutline, counter: mdiCounter, date: mdiCalendar, datetime: mdiCalendarClock, @@ -235,6 +236,8 @@ export const SENSOR_ENTITIES = [ "weather", ]; +export const ASSIST_ENTITIES = ["conversation", "stt", "tts"]; + /** Domains that render an input element instead of a text value when displayed in a row. * Those rows should then not show a cursor pointer when hovered (which would normally * be the default) unless the element itself enforces it (e.g. a button). Also those elements diff --git a/src/panels/config/devices/ha-config-device-page.ts b/src/panels/config/devices/ha-config-device-page.ts index 4ea0dd37d235..35590f6ffd2b 100644 --- a/src/panels/config/devices/ha-config-device-page.ts +++ b/src/panels/config/devices/ha-config-device-page.ts @@ -24,7 +24,7 @@ import { customElement, property, state } from "lit/decorators"; import { ifDefined } from "lit/directives/if-defined"; import memoizeOne from "memoize-one"; import { isComponentLoaded } from "../../../common/config/is_component_loaded"; -import { SENSOR_ENTITIES } from "../../../common/const"; +import { SENSOR_ENTITIES, ASSIST_ENTITIES } from "../../../common/const"; import { computeDomain } from "../../../common/entity/compute_domain"; import { computeStateDomain } from "../../../common/entity/compute_state_domain"; import { computeStateName } from "../../../common/entity/compute_state_name"; @@ -190,26 +190,42 @@ export class HaConfigDevicePage extends LitElement { private _entitiesByCategory = memoizeOne( (entities: EntityRegistryEntry[]) => { - const result = groupBy(entities, (entry) => - entry.entity_category - ? entry.entity_category - : computeDomain(entry.entity_id) === "event" - ? "event" - : SENSOR_ENTITIES.includes(computeDomain(entry.entity_id)) - ? "sensor" - : "control" - ) as Record< + const result = groupBy(entities, (entry) => { + const domain = computeDomain(entry.entity_id); + + if (entry.entity_category) { + return entry.entity_category; + } + + if (domain === "event" || domain === "notify") { + return domain; + } + + if (SENSOR_ENTITIES.includes(domain)) { + return "sensor"; + } + + if (ASSIST_ENTITIES.includes(domain)) { + return "assist"; + } + + return "control"; + }) as Record< | "control" | "event" | "sensor" + | "assist" + | "notify" | NonNullable, EntityRegistryStateEntry[] >; for (const key of [ + "assist", "config", "control", "diagnostic", "event", + "notify", "sensor", ]) { if (!(key in result)) { @@ -854,7 +870,15 @@ export class HaConfigDevicePage extends LitElement {
${( - ["control", "sensor", "event", "config", "diagnostic"] as const + [ + "control", + "sensor", + "notify", + "event", + "assist", + "config", + "diagnostic", + ] as const ).map((category) => // Make sure we render controls if no other cards will be rendered entitiesByCategory[category].length > 0 || diff --git a/src/panels/lovelace/common/generate-lovelace-config.ts b/src/panels/lovelace/common/generate-lovelace-config.ts index d1da6d9c6990..6f75cf3559c5 100644 --- a/src/panels/lovelace/common/generate-lovelace-config.ts +++ b/src/panels/lovelace/common/generate-lovelace-config.ts @@ -1,5 +1,5 @@ import { HassEntities, HassEntity } from "home-assistant-js-websocket"; -import { SENSOR_ENTITIES } from "../../../common/const"; +import { SENSOR_ENTITIES, ASSIST_ENTITIES } from "../../../common/const"; import { computeDomain } from "../../../common/entity/compute_domain"; import { computeStateDomain } from "../../../common/entity/compute_state_domain"; import { computeStateName } from "../../../common/entity/compute_state_name"; @@ -35,18 +35,16 @@ import { ButtonsHeaderFooterConfig } from "../header-footer/types"; const HIDE_DOMAIN = new Set([ "automation", "configurator", - "conversation", "device_tracker", "event", "geo_location", "notify", "persistent_notification", "script", - "stt", "sun", "todo", - "tts", "zone", + ...ASSIST_ENTITIES, ]); const HIDE_PLATFORM = new Set(["mobile_app"]); diff --git a/src/translations/en.json b/src/translations/en.json index 94bff52f7d3f..d24198c6fc1e 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -4012,6 +4012,8 @@ "event": "Events", "sensor": "Sensors", "diagnostic": "Diagnostic", + "notify": "Notifiers", + "assist": "[%key:ui::panel::lovelace::menu::assist%]", "config": "Configuration", "add_entities_lovelace": "Add to dashboard", "none": "This device has no entities",