Skip to content

Commit

Permalink
Split out service entities (#21076)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
balloob authored Jun 18, 2024
1 parent 27afe9e commit 9c153bb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/common/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
mdiFormatListBulleted,
mdiFormatListCheckbox,
mdiFormTextbox,
mdiForumOutline,
mdiGauge,
mdiGoogleAssistant,
mdiGoogleCirclesCommunities,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
46 changes: 35 additions & 11 deletions src/panels/config/devices/ha-config-device-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<EntityRegistryEntry["entity_category"]>,
EntityRegistryStateEntry[]
>;
for (const key of [
"assist",
"config",
"control",
"diagnostic",
"event",
"notify",
"sensor",
]) {
if (!(key in result)) {
Expand Down Expand Up @@ -854,7 +870,15 @@ export class HaConfigDevicePage extends LitElement {
</div>
<div class="column">
${(
["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 ||
Expand Down
6 changes: 2 additions & 4 deletions src/panels/lovelace/common/generate-lovelace-config.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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"]);
Expand Down
2 changes: 2 additions & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9c153bb

Please sign in to comment.