Add download diagnostics to Thread panel (#15550)

This commit is contained in:
Paulus Schoutsen 2023-02-22 11:29:58 -05:00 committed by GitHub
parent e46803cb4e
commit 6b9e0405d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,10 @@ import { customElement, property, state } from "lit/decorators";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
import { isComponentLoaded } from "../../../../../common/config/is_component_loaded"; import { isComponentLoaded } from "../../../../../common/config/is_component_loaded";
import { stringCompare } from "../../../../../common/string/compare"; import { stringCompare } from "../../../../../common/string/compare";
import { extractSearchParam } from "../../../../../common/url/search-params";
import "../../../../../components/ha-card"; import "../../../../../components/ha-card";
import { getSignedPath } from "../../../../../data/auth";
import { getConfigEntryDiagnosticsDownloadUrl } from "../../../../../data/diagnostics";
import { getOTBRInfo } from "../../../../../data/otbr"; import { getOTBRInfo } from "../../../../../data/otbr";
import { import {
listThreadDataSets, listThreadDataSets,
@ -20,6 +23,7 @@ import { SubscribeMixin } from "../../../../../mixins/subscribe-mixin";
import { haStyle } from "../../../../../resources/styles"; import { haStyle } from "../../../../../resources/styles";
import { HomeAssistant } from "../../../../../types"; import { HomeAssistant } from "../../../../../types";
import { brandsUrl } from "../../../../../util/brands-url"; import { brandsUrl } from "../../../../../util/brands-url";
import { fileDownload } from "../../../../../util/file_download";
interface ThreadNetwork { interface ThreadNetwork {
name: string; name: string;
@ -33,6 +37,8 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) {
@property({ type: Boolean }) public narrow!: boolean; @property({ type: Boolean }) public narrow!: boolean;
@state() private _configEntryId: string | null = null;
@state() private _routers: ThreadRouter[] = []; @state() private _routers: ThreadRouter[] = [];
@state() private _datasets: ThreadDataSet[] = []; @state() private _datasets: ThreadDataSet[] = [];
@ -47,6 +53,19 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) {
.path=${mdiDotsVertical} .path=${mdiDotsVertical}
slot="trigger" slot="trigger"
></ha-icon-button> ></ha-icon-button>
<a
href=${getConfigEntryDiagnosticsDownloadUrl(
this._configEntryId || ""
)}
target="_blank"
@click=${this._signUrl}
>
<mwc-list-item>
${this.hass.localize(
"ui.panel.config.integrations.config_entry.download_diagnostics"
)}
</mwc-list-item>
</a>
<mwc-list-item @click=${this._addOTBR} <mwc-list-item @click=${this._addOTBR}
>${this.hass.localize( >${this.hass.localize(
"ui.panel.config.thread.add_open_thread_border_router" "ui.panel.config.thread.add_open_thread_border_router"
@ -177,6 +196,8 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) {
super.firstUpdated(changedProps); super.firstUpdated(changedProps);
this._refresh(); this._refresh();
this._configEntryId = extractSearchParam("config_entry");
} }
private _groupRoutersByNetwork = memoizeOne( private _groupRoutersByNetwork = memoizeOne(
@ -226,6 +247,16 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) {
}); });
} }
private async _signUrl(ev) {
const anchor = ev.target.closest("a");
ev.preventDefault();
const signedUrl = await getSignedPath(
this.hass,
anchor.getAttribute("href")
);
fileDownload(signedUrl.path);
}
private _addOTBR() { private _addOTBR() {
showConfigFlowDialog(this, { showConfigFlowDialog(this, {
dialogClosedCallback: () => { dialogClosedCallback: () => {
@ -245,6 +276,9 @@ export class ThreadConfigPanel extends SubscribeMixin(LitElement) {
margin: 0 auto; margin: 0 auto;
direction: ltr; direction: ltr;
} }
ha-button-menu a {
text-decoration: none;
}
.routers { .routers {
padding-bottom: 0; padding-bottom: 0;
} }