Add all devices and entities link to integration page (#16781)

This commit is contained in:
Bram Kragten 2023-06-05 17:52:11 +02:00 committed by GitHub
parent 45d260f0ce
commit fcacdf6534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,8 +10,10 @@ import {
mdiCloud, mdiCloud,
mdiCog, mdiCog,
mdiDelete, mdiDelete,
mdiDevices,
mdiDotsVertical, mdiDotsVertical,
mdiDownload, mdiDownload,
mdiHandExtendedOutline,
mdiOpenInNew, mdiOpenInNew,
mdiPackageVariant, mdiPackageVariant,
mdiPlayCircleOutline, mdiPlayCircleOutline,
@ -19,6 +21,7 @@ import {
mdiReload, mdiReload,
mdiReloadAlert, mdiReloadAlert,
mdiRenameBox, mdiRenameBox,
mdiShapeOutline,
mdiStopCircleOutline, mdiStopCircleOutline,
} from "@mdi/js"; } from "@mdi/js";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
@ -228,6 +231,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
); );
}); });
const devices = this._getDevices(configEntries, this.hass.devices);
const entities = this._getEntities(configEntries, this._entities);
const services = !devices.some((device) => device.entry_type !== "service");
return html` return html`
<hass-subpage <hass-subpage
.hass=${this.hass} .hass=${this.hass}
@ -273,28 +281,47 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
</div> </div>
<div class="card-actions"> <div class="card-actions">
${this._logInfo ${devices.length > 0
? html`<ha-list-item ? html`<a
@request-selected=${this._logInfo.level === href=${devices.length === 1
LogSeverity.DEBUG ? `/config/devices/device/${devices[0].id}`
? this._handleDisableDebugLogging : `/config/devices/dashboard?historyBack=1&domain=${this.domain}`}
: this._handleEnableDebugLogging}
graphic="icon"
> >
${this._logInfo.level === LogSeverity.DEBUG <ha-list-item hasMeta graphic="icon">
? this.hass.localize( <ha-svg-icon
"ui.panel.config.integrations.config_entry.disable_debug_logging" .path=${services
) ? mdiHandExtendedOutline
: this.hass.localize( : mdiDevices}
"ui.panel.config.integrations.config_entry.enable_debug_logging" slot="graphic"
)} ></ha-svg-icon>
<ha-svg-icon ${this.hass.localize(
slot="graphic" `ui.panel.config.integrations.config_entry.${
.path=${this._logInfo.level === LogSeverity.DEBUG services ? "services" : "devices"
? mdiBugStop }`,
: mdiBugPlay} "count",
></ha-svg-icon> devices.length
</ha-list-item>` )}
<ha-icon-next slot="meta"></ha-icon-next>
</ha-list-item>
</a>`
: ""}
${entities.length > 0
? html`<a
href=${`/config/entities?historyBack=1&domain=${this.domain}`}
>
<ha-list-item hasMeta graphic="icon">
<ha-svg-icon
.path=${mdiShapeOutline}
slot="graphic"
></ha-svg-icon>
${this.hass.localize(
`ui.panel.config.integrations.config_entry.entities`,
"count",
entities.length
)}
<ha-icon-next slot="meta"></ha-icon-next>
</ha-list-item>
</a>`
: ""} : ""}
${this._manifest ${this._manifest
? html`<a ? html`<a
@ -344,6 +371,32 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
</ha-list-item> </ha-list-item>
</a>` </a>`
: ""} : ""}
${this._logInfo
? html`<ha-list-item
@request-selected=${this._logInfo.level ===
LogSeverity.DEBUG
? this._handleDisableDebugLogging
: this._handleEnableDebugLogging}
graphic="icon"
>
${this._logInfo.level === LogSeverity.DEBUG
? this.hass.localize(
"ui.panel.config.integrations.config_entry.disable_debug_logging"
)
: this.hass.localize(
"ui.panel.config.integrations.config_entry.enable_debug_logging"
)}
<ha-svg-icon
slot="graphic"
class=${this._logInfo.level === LogSeverity.DEBUG
? "warning"
: ""}
.path=${this._logInfo.level === LogSeverity.DEBUG
? mdiBugStop
: mdiBugPlay}
></ha-svg-icon>
</ha-list-item>`
: ""}
</div> </div>
</ha-card> </ha-card>
</div> </div>
@ -510,9 +563,9 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
} }
} }
const devices = this._getDevices(item, this.hass.devices); const devices = this._getConfigEntryDevices(item);
const services = this._getServices(item, this.hass.devices); const services = this._getConfigEntryServices(item);
const entities = this._getEntities(item, this._entities); const entities = this._getConfigEntryEntities(item);
let devicesLine: (TemplateResult | string)[] = []; let devicesLine: (TemplateResult | string)[] = [];
@ -809,49 +862,77 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
private _getEntities = memoizeOne( private _getEntities = memoizeOne(
( (
configEntry: ConfigEntry, configEntry: ConfigEntry[],
entityRegistryEntries: EntityRegistryEntry[] entityRegistryEntries: EntityRegistryEntry[]
): EntityRegistryEntry[] => { ): EntityRegistryEntry[] => {
if (!entityRegistryEntries) { if (!entityRegistryEntries) {
return []; return [];
} }
const entryIds = configEntry.map((entry) => entry.entry_id);
return entityRegistryEntries.filter( return entityRegistryEntries.filter(
(entity) => entity.config_entry_id === configEntry.entry_id (entity) =>
entity.config_entry_id && entryIds.includes(entity.config_entry_id)
); );
} }
); );
private _getDevices = memoizeOne( private _getDevices = memoizeOne(
( (
configEntry: ConfigEntry, configEntry: ConfigEntry[],
deviceRegistryEntries: HomeAssistant["devices"] deviceRegistryEntries: HomeAssistant["devices"]
): DeviceRegistryEntry[] => { ): DeviceRegistryEntry[] => {
if (!deviceRegistryEntries) { if (!deviceRegistryEntries) {
return []; return [];
} }
return Object.values(deviceRegistryEntries).filter( const entryIds = configEntry.map((entry) => entry.entry_id);
(device) => return Object.values(deviceRegistryEntries).filter((device) =>
device.config_entries.includes(configEntry.entry_id) && device.config_entries.some((entryId) => entryIds.includes(entryId))
device.entry_type !== "service"
); );
} }
); );
private _getServices = memoizeOne( private _getConfigEntryEntities = (
( configEntry: ConfigEntry
configEntry: ConfigEntry, ): EntityRegistryEntry[] => {
deviceRegistryEntries: HomeAssistant["devices"] const entries = this._domainConfigEntries(
): DeviceRegistryEntry[] => { this.domain,
if (!deviceRegistryEntries) { this._extraConfigEntries || this.configEntries
return []; );
} const entityRegistryEntries = this._getEntities(entries, this._entities);
return Object.values(deviceRegistryEntries).filter( return entityRegistryEntries.filter(
(device) => (entity) => entity.config_entry_id === configEntry.entry_id
device.config_entries.includes(configEntry.entry_id) && );
device.entry_type === "service" };
);
} private _getConfigEntryDevices = (
); configEntry: ConfigEntry
): DeviceRegistryEntry[] => {
const entries = this._domainConfigEntries(
this.domain,
this._extraConfigEntries || this.configEntries
);
const deviceRegistryEntries = this._getDevices(entries, this.hass.devices);
return Object.values(deviceRegistryEntries).filter(
(device) =>
device.config_entries.includes(configEntry.entry_id) &&
device.entry_type !== "service"
);
};
private _getConfigEntryServices = (
configEntry: ConfigEntry
): DeviceRegistryEntry[] => {
const entries = this._domainConfigEntries(
this.domain,
this._extraConfigEntries || this.configEntries
);
const deviceRegistryEntries = this._getDevices(entries, this.hass.devices);
return Object.values(deviceRegistryEntries).filter(
(device) =>
device.config_entries.includes(configEntry.entry_id) &&
device.entry_type === "service"
);
};
private _showOptions(ev) { private _showOptions(ev) {
showOptionsFlowDialog( showOptionsFlowDialog(
@ -1223,6 +1304,9 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
.attention { .attention {
primary-color: var(--error-color); primary-color: var(--error-color);
} }
.warning {
color: var(--warning-color);
}
.state-error { .state-error {
--state-message-color: var(--error-color); --state-message-color: var(--error-color);
--text-on-state-color: var(--text-primary-color); --text-on-state-color: var(--text-primary-color);