Skip to content

Commit

Permalink
Add grouping by area and domain in voice assistant expose data table (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
piitaya authored May 15, 2024
1 parent c864b34 commit be26f8b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import { voiceAssistantTabs } from "./ha-config-voice-assistants";
import { showExposeEntityDialog } from "./show-dialog-expose-entity";
import { showVoiceSettingsDialog } from "./show-dialog-voice-settings";
import { storage } from "../../../common/decorators/storage";
import { domainToName } from "../../../data/integration";
import { computeDomain } from "../../../common/entity/compute_domain";

@customElement("ha-config-voice-assistants-expose")
export class VoiceAssistantsExpose extends LitElement {
Expand Down Expand Up @@ -96,6 +98,12 @@ export class VoiceAssistantsExpose extends LitElement {
})
private _activeSorting?: SortingChangedEvent;

@storage({ key: "devices-table-grouping", state: false, subscribe: false })
private _activeGrouping?: string;

@storage({ key: "devices-table-collapsed", state: false, subscribe: false })
private _activeCollapsed?: string;

@query("hass-tabs-subpage-data-table", true)
private _dataTable!: HaTabsSubpageDataTable;

Expand Down Expand Up @@ -136,9 +144,19 @@ export class VoiceAssistantsExpose extends LitElement {
<div class="secondary">${entry.entity_id}</div>
`,
},
domain: {
title: localize(
"ui.panel.config.voice_assistants.expose.headers.domain"
),
sortable: false,
hidden: true,
filterable: true,
groupable: true,
},
area: {
title: localize("ui.panel.config.voice_assistants.expose.headers.area"),
sortable: true,
groupable: true,
hidden: narrow,
filterable: true,
width: "15%",
Expand Down Expand Up @@ -252,6 +270,7 @@ export class VoiceAssistantsExpose extends LitElement {

private _filteredEntities = memoize(
(
localize: LocalizeFunc,
entities: Record<string, ExtEntityRegistryEntry>,
exposedEntities: Record<string, ExposeEntitySettings>,
devices: HomeAssistant["devices"],
Expand Down Expand Up @@ -332,6 +351,7 @@ export class VoiceAssistantsExpose extends LitElement {
this.hass.localize(
"ui.panel.config.entities.picker.unnamed_entity"
),
domain: domainToName(localize, computeDomain(entityState.entity_id)),
area: area ? area.name : "—",
assistants: Object.keys(
exposedEntities?.[entityState.entity_id]
Expand Down Expand Up @@ -479,6 +499,7 @@ export class VoiceAssistantsExpose extends LitElement {
}

const filteredEntities = this._filteredEntities(
this.hass.localize,
this._extEntities,
this.exposedEntities,
this.hass.devices,
Expand Down Expand Up @@ -515,8 +536,12 @@ export class VoiceAssistantsExpose extends LitElement {
.selected=${this._selectedEntities.length}
clickable
.initialSorting=${this._activeSorting}
.initialGroupColumn=${this._activeGrouping}
.initialCollapsedGroups=${this._activeCollapsed}
@sorting-changed=${this._handleSortingChanged}
@selection-changed=${this._handleSelectionChanged}
@grouping-changed=${this._handleGroupingChanged}
@collapsed-changed=${this._handleCollapseChanged}
@clear-filter=${this._clearFilter}
@search-changed=${this._handleSearchChange}
@row-click=${this._openEditEntry}
Expand Down Expand Up @@ -711,6 +736,14 @@ export class VoiceAssistantsExpose extends LitElement {
this._activeSorting = ev.detail;
}

private _handleGroupingChanged(ev: CustomEvent) {
this._activeGrouping = ev.detail.value;
}

private _handleCollapseChanged(ev: CustomEvent) {
this._activeCollapsed = ev.detail.value;
}

static get styles(): CSSResultGroup {
return [
haStyle,
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,7 @@
"headers": {
"name": "Name",
"area": "Area",
"domain": "Domain",
"assistants": "Assistants",
"aliases": "Aliases"
},
Expand Down

0 comments on commit be26f8b

Please sign in to comment.