Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a button for launching the ZHA options flow to reconfigure the radio #13506

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
TemplateResult,
} from "lit";
import { customElement, property, state } from "lit/decorators";
import {
ConfigEntry,
getConfigEntries,
} from "../../../../../data/config_entries";
import { computeRTL } from "../../../../../common/util/compute_rtl";
import "../../../../../components/ha-card";
import "../../../../../components/ha-fab";
import { fileDownload } from "../../../../../util/file_download";
import "../../../../../components/ha-icon-next";
import "../../../../../layouts/hass-tabs-subpage";
import type { PageNavigation } from "../../../../../layouts/hass-tabs-subpage";
import { showOptionsFlowDialog } from "../../../../../dialogs/config-flow/show-dialog-options-flow";
import { haStyle } from "../../../../../resources/styles";
import type { HomeAssistant, Route } from "../../../../../types";
import "../../../ha-config-section";
Expand Down Expand Up @@ -114,13 +119,14 @@ class ZHAConfigDashboard extends LitElement {
</div>`
: ""}
</ha-card>
${this._networkSettings
? html` <ha-card
header=${this.hass.localize(
"ui.panel.config.zha.configuration_page.network_settings_title"
)}
>
<div class="card-content network-settings">
<ha-card
class="network-settings"
header=${this.hass.localize(
"ui.panel.config.zha.configuration_page.network_settings_title"
)}
>
${this._networkSettings
? html`<div class="card-content network-settings">
<div>
<strong>PAN ID:</strong>
${this._networkSettings.settings.network_info.pan_id}
Expand All @@ -145,20 +151,25 @@ class ZHAConfigDashboard extends LitElement {
<strong>Radio type:</strong>
${this._networkSettings.radio_type}
</div>
</div>
<div class="card-actions">
<ha-progress-button
@click=${this._createAndDownloadBackup}
.progress=${this._generatingBackup}
.disabled=${this._generatingBackup}
>
${this.hass.localize(
"ui.panel.config.zha.configuration_page.download_backup"
)}
</ha-progress-button>
</div>
</ha-card>`
: ""}
</div>`
: ""}
<div class="card-actions">
<ha-progress-button
@click=${this._createAndDownloadBackup}
.progress=${this._generatingBackup}
.disabled=${!this._networkSettings || this._generatingBackup}
>
${this.hass.localize(
"ui.panel.config.zha.configuration_page.download_backup"
)}
</ha-progress-button>
<mwc-button class="warning" @click=${this._openOptionFlow}>
${this.hass.localize(
"ui.panel.config.zha.configuration_page.migrate_radio"
)}
</mwc-button>
</div>
</ha-card>
${this._configuration
? Object.entries(this._configuration.schemas).map(
([section, schema]) => html`<ha-card
Expand Down Expand Up @@ -253,6 +264,22 @@ class ZHAConfigDashboard extends LitElement {
fileDownload(backupJSON, `${basename}.json`);
}

private async _openOptionFlow() {
if (!this.configEntryId) {
return;
}

const configEntries: ConfigEntry[] = await getConfigEntries(this.hass, {
domain: "zha",
});

const configEntry = configEntries.find(
(entry) => entry.entry_id === this.configEntryId
);

showOptionsFlowDialog(this, configEntry!);
}

private _dataChanged(ev) {
this._configuration!.data[ev.currentTarget!.section] = ev.detail.value;
}
Expand Down Expand Up @@ -282,6 +309,12 @@ class ZHAConfigDashboard extends LitElement {
word-break: break-all;
margin-top: 2px;
}

.network-settings > .card-actions {
display: flex;
justify-content: space-between;
align-items: center;
}
`,
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3021,7 +3021,8 @@
"configuration_page": {
"shortcuts_title": "Shortcuts",
"update_button": "Update Configuration",
"download_backup": "Download Network Backup",
"download_backup": "Download Backup",
"migrate_radio": "Migrate Radio",
"network_settings_title": "Network Settings"
},
"add_device_page": {
Expand Down