Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Feb 10, 2025
1 parent 3e8217d commit 212cf48
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
8 changes: 4 additions & 4 deletions src/data/config_entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ export interface ConfigEntry {
error_reason_translation_placeholders: Record<string, string> | null;
}

export interface SubConfigEntry {
export interface SubEntry {
subentry_id: string;
subentry_type: string;
title: string;
unique_id: string;
}

export const getSubConfigEntries = (hass: HomeAssistant, entry_id: string) =>
hass.callWS<SubConfigEntry[]>({
export const getSubEntries = (hass: HomeAssistant, entry_id: string) =>
hass.callWS<SubEntry[]>({
type: "config_entries/subentries/list",
entry_id,
});

export const deleteSubConfigEntry = (
export const deleteSubEntry = (
hass: HomeAssistant,
entry_id: string,
subentry_id: string
Expand Down
23 changes: 10 additions & 13 deletions src/panels/config/devices/ha-config-devices-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ import "../../../components/ha-icon-button";
import "../../../components/ha-md-menu-item";
import "../../../components/ha-sub-menu";
import { createAreaRegistryEntry } from "../../../data/area_registry";
import type { ConfigEntry, SubConfigEntry } from "../../../data/config_entries";
import {
getSubConfigEntries,
sortConfigEntries,
} from "../../../data/config_entries";
import type { ConfigEntry, SubEntry } from "../../../data/config_entries";
import { getSubEntries, sortConfigEntries } from "../../../data/config_entries";
import { fullEntitiesContext } from "../../../data/context";
import type { DataTableFilters } from "../../../data/data_table_filters";
import {
Expand Down Expand Up @@ -111,7 +108,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {

@property({ attribute: false }) public entries!: ConfigEntry[];

@state() private _subConfigEntries?: SubConfigEntry[];
@state() private _subEntries?: SubEntry[];

@state()
@consume({ context: fullEntitiesContext, subscribe: true })
Expand Down Expand Up @@ -224,7 +221,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
private _setFiltersFromUrl() {
const domain = this._searchParms.get("domain");
const configEntry = this._searchParms.get("config_entry");
const subConfigEntry = this._searchParms.get("sub_entry");
const subEntry = this._searchParms.get("sub_entry");
const label = this._searchParms.has("label");

if (!domain && !configEntry && !label) {
Expand All @@ -250,7 +247,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
items: undefined,
},
sub_config_entry: {
value: subConfigEntry ? [subConfigEntry] : [],
value: subEntry ? [subEntry] : [],
items: undefined,
},
};
Expand Down Expand Up @@ -367,8 +364,8 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
)
)
);
if (!this._subConfigEntries) {
this._loadSubConfigEntries(configEntryId);
if (!this._subEntries) {
this._loadSubEntries(configEntryId);
}
} else if (
key === "ha-filter-integrations" &&
Expand Down Expand Up @@ -795,7 +792,7 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
.config_entry.value.length === 1 &&
Array.isArray(this._filters.sub_config_entry?.value) &&
this._filters.sub_config_entry.value.length
? html` (${this._subConfigEntries?.find(
? html` (${this._subEntries?.find(
(entry) =>
entry.subentry_id ===
this._filters.sub_config_entry!.value![0]
Expand Down Expand Up @@ -933,8 +930,8 @@ export class HaConfigDeviceDashboard extends SubscribeMixin(LitElement) {
`;
}

private async _loadSubConfigEntries(entryId: string) {
this._subConfigEntries = await getSubConfigEntries(this.hass, entryId);
private async _loadSubEntries(entryId: string) {
this._subEntries = await getSubEntries(this.hass, entryId);
}

private _filterExpanded(ev) {
Expand Down
23 changes: 10 additions & 13 deletions src/panels/config/entities/ha-config-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,8 @@ import "../../../components/ha-icon-button";
import "../../../components/ha-md-menu-item";
import "../../../components/ha-sub-menu";
import "../../../components/ha-svg-icon";
import type { ConfigEntry, SubConfigEntry } from "../../../data/config_entries";
import {
getConfigEntries,
getSubConfigEntries,
} from "../../../data/config_entries";
import type { ConfigEntry, SubEntry } from "../../../data/config_entries";
import { getConfigEntries, getSubEntries } from "../../../data/config_entries";
import { fullEntitiesContext } from "../../../data/context";
import type {
DataTableFiltersItems,
Expand Down Expand Up @@ -149,7 +146,7 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {

@state() private _entries?: ConfigEntry[];

@state() private _subConfigEntries?: SubConfigEntry[];
@state() private _subEntries?: SubEntry[];

@state() private _manifests?: IntegrationManifest[];

Expand Down Expand Up @@ -545,8 +542,8 @@ export class HaConfigEntities extends SubscribeMixin(LitElement) {
entity.config_subentry_id &&
(filter as string[]).includes(entity.config_subentry_id)
);
if (!this._subConfigEntries) {
this._loadSubConfigEntries(this._filters.config_entry[0]);
if (!this._subEntries) {
this._loadSubEntries(this._filters.config_entry[0]);
}
} else if (
key === "ha-filter-integrations" &&
Expand Down Expand Up @@ -941,7 +938,7 @@ ${
.config_entry.length === 1 &&
Array.isArray(this._filters.sub_config_entry) &&
this._filters.sub_config_entry.length
? html` (${this._subConfigEntries?.find(
? html` (${this._subEntries?.find(
(entry) =>
entry.subentry_id === this._filters.sub_config_entry![0]
)?.title || this._filters.sub_config_entry[0]})`
Expand Down Expand Up @@ -1058,7 +1055,7 @@ ${
private _setFiltersFromUrl() {
const domain = this._searchParms.get("domain");
const configEntry = this._searchParms.get("config_entry");
const subConfigEntry = this._searchParms.get("sub_entry");
const subEntry = this._searchParms.get("sub_entry");
const label = this._searchParms.has("label");

if (!domain && !configEntry && !label) {
Expand All @@ -1071,7 +1068,7 @@ ${
"ha-filter-states": [],
"ha-filter-integrations": domain ? [domain] : [],
config_entry: configEntry ? [configEntry] : [],
sub_config_entry: subConfigEntry ? [subConfigEntry] : [],
sub_config_entry: subEntry ? [subEntry] : [],
};
this._filterLabel();
}
Expand Down Expand Up @@ -1421,8 +1418,8 @@ ${rejected
this._entries = await getConfigEntries(this.hass);
}

private async _loadSubConfigEntries(entryId: string) {
this._subConfigEntries = await getSubConfigEntries(this.hass, entryId);
private async _loadSubEntries(entryId: string) {
this._subEntries = await getSubEntries(this.hass, entryId);
}

private _addDevice() {
Expand Down
26 changes: 11 additions & 15 deletions src/panels/config/integrations/ha-config-integration-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ import { getSignedPath } from "../../../data/auth";
import type {
ConfigEntry,
DisableConfigEntryResult,
SubConfigEntry,
SubEntry,
} from "../../../data/config_entries";
import {
ERROR_STATES,
RECOVERABLE_STATES,
deleteConfigEntry,
deleteSubConfigEntry,
deleteSubEntry,
disableConfigEntry,
enableConfigEntry,
getConfigEntries,
getSubConfigEntries,
getSubEntries,
reloadConfigEntry,
updateConfigEntry,
} from "../../../data/config_entries";
Expand Down Expand Up @@ -177,7 +177,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {

@state() private _domainEntities: Record<string, string[]> = {};

@state() private _subEntries: Record<string, SubConfigEntry[]> = {};
@state() private _subEntries: Record<string, SubEntry[]> = {};

private _configPanel = memoizeOne(
(domain: string, panels: HomeAssistant["panels"]): string | undefined =>
Expand Down Expand Up @@ -692,7 +692,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
devices: DeviceRegistryEntry[],
services: DeviceRegistryEntry[],
entities: EntityRegistryEntry[],
subItem?: SubConfigEntry
subItem?: SubEntry
) {
let devicesLine: (TemplateResult | string)[] = [];
for (const [items, localizeKey] of [
Expand Down Expand Up @@ -1036,7 +1036,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
${subEntries.map((subEntry) => this._renderSubEntry(item, subEntry))}`;
}

private _renderSubEntry(configEntry: ConfigEntry, subEntry: SubConfigEntry) {
private _renderSubEntry(configEntry: ConfigEntry, subEntry: SubEntry) {
const devices = this._getConfigEntryDevices(configEntry).filter((device) =>
device.config_entries_subentries[configEntry.entry_id]?.includes(
subEntry.subentry_id
Expand All @@ -1056,7 +1056,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
class="sub-entry"
data-entry-id=${configEntry.entry_id}
.configEntry=${configEntry}
.subConfigEntry=${subEntry}
.subEntry=${subEntry}
>
<span slot="headline">${subEntry.title}</span>
<span slot="supporting-text"
Expand Down Expand Up @@ -1141,7 +1141,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
this._extraConfigEntries || this.configEntries
)?.map((entry) =>
entry.num_subentries
? getSubConfigEntries(this.hass, entry.entry_id).then((subEntries) => ({
? getSubEntries(this.hass, entry.entry_id).then((subEntries) => ({
entry_id: entry.entry_id,
subEntries,
}))
Expand Down Expand Up @@ -1309,7 +1309,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
(ev.target as HTMLElement).closest(".sub-entry") as any
).configEntry;
const subEntry = ((ev.target as HTMLElement).closest(".sub-entry") as any)
.subConfigEntry;
.subEntry;

showSubConfigFlowDialog(
this,
Expand All @@ -1327,7 +1327,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
(ev.target as HTMLElement).closest(".sub-entry") as any
).configEntry;
const subEntry = ((ev.target as HTMLElement).closest(".sub-entry") as any)
.subConfigEntry;
.subEntry;
const confirmed = await showConfirmationDialog(this, {
title: this.hass.localize(
"ui.panel.config.integrations.config_entry.delete_confirm_title",
Expand All @@ -1344,11 +1344,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
if (!confirmed) {
return;
}
await deleteSubConfigEntry(
this.hass,
configEntry.entry_id,
subEntry.subentry_id
);
await deleteSubEntry(this.hass, configEntry.entry_id, subEntry.subentry_id);
}

private _handleDisable(ev: Event): void {
Expand Down

0 comments on commit 212cf48

Please sign in to comment.