mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 19:09:48 +00:00
Add support for exact % progress reports in options flow (#25082)
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
@@ -9,7 +9,10 @@ import { fireEvent } from "../../common/dom/fire_event";
|
||||
import "../../components/ha-dialog";
|
||||
import "../../components/ha-icon-button";
|
||||
import type { DataEntryFlowStep } from "../../data/data_entry_flow";
|
||||
import { subscribeDataEntryFlowProgressed } from "../../data/data_entry_flow";
|
||||
import {
|
||||
subscribeDataEntryFlowProgress,
|
||||
subscribeDataEntryFlowProgressed,
|
||||
} from "../../data/data_entry_flow";
|
||||
import { haStyleDialog } from "../../resources/styles";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import { documentationUrl } from "../../util/documentation-url";
|
||||
@@ -52,6 +55,8 @@ class DataEntryFlowDialog extends LitElement {
|
||||
|
||||
@state() private _loading?: LoadingReason;
|
||||
|
||||
@state() private _progress?: number;
|
||||
|
||||
private _instance = instance;
|
||||
|
||||
@state() private _step:
|
||||
@@ -62,7 +67,7 @@ class DataEntryFlowDialog extends LitElement {
|
||||
|
||||
@state() private _handler?: string;
|
||||
|
||||
private _unsubDataEntryFlowProgressed?: Promise<UnsubscribeFunc>;
|
||||
private _unsubDataEntryFlowProgress?: UnsubscribeFunc;
|
||||
|
||||
public async showDialog(params: DataEntryFlowDialogParams): Promise<void> {
|
||||
this._params = params;
|
||||
@@ -160,11 +165,9 @@ class DataEntryFlowDialog extends LitElement {
|
||||
this._step = undefined;
|
||||
this._params = undefined;
|
||||
this._handler = undefined;
|
||||
if (this._unsubDataEntryFlowProgressed) {
|
||||
this._unsubDataEntryFlowProgressed.then((unsub) => {
|
||||
unsub();
|
||||
});
|
||||
this._unsubDataEntryFlowProgressed = undefined;
|
||||
if (this._unsubDataEntryFlowProgress) {
|
||||
this._unsubDataEntryFlowProgress();
|
||||
this._unsubDataEntryFlowProgress = undefined;
|
||||
}
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
}
|
||||
@@ -255,7 +258,9 @@ class DataEntryFlowDialog extends LitElement {
|
||||
.params=${this._params}
|
||||
.step=${this._step}
|
||||
.hass=${this.hass}
|
||||
.domain=${this._step.handler}
|
||||
.handler=${this._step.handler}
|
||||
.domain=${this._params.domain ??
|
||||
this._step.handler}
|
||||
></step-flow-abort>
|
||||
`
|
||||
: this._step.type === "progress"
|
||||
@@ -264,6 +269,7 @@ class DataEntryFlowDialog extends LitElement {
|
||||
.flowConfig=${this._params.flowConfig}
|
||||
.step=${this._step}
|
||||
.hass=${this.hass}
|
||||
.progress=${this._progress}
|
||||
></step-flow-progress>
|
||||
`
|
||||
: this._step.type === "menu"
|
||||
@@ -339,20 +345,28 @@ class DataEntryFlowDialog extends LitElement {
|
||||
}
|
||||
|
||||
private async _subscribeDataEntryFlowProgressed() {
|
||||
if (this._unsubDataEntryFlowProgressed) {
|
||||
if (this._unsubDataEntryFlowProgress) {
|
||||
return;
|
||||
}
|
||||
this._unsubDataEntryFlowProgressed = subscribeDataEntryFlowProgressed(
|
||||
this.hass.connection,
|
||||
async (ev) => {
|
||||
this._progress = undefined;
|
||||
const unsubs = [
|
||||
subscribeDataEntryFlowProgressed(this.hass.connection, (ev) => {
|
||||
if (ev.data.flow_id !== this._step?.flow_id) {
|
||||
return;
|
||||
}
|
||||
this._processStep(
|
||||
this._params!.flowConfig.fetchFlow(this.hass, this._step.flow_id)
|
||||
);
|
||||
}
|
||||
);
|
||||
this._progress = undefined;
|
||||
}),
|
||||
subscribeDataEntryFlowProgress(this.hass.connection, (ev) => {
|
||||
// ha-progress-ring has an issue with 0 so we round up
|
||||
this._progress = Math.ceil(ev.data.progress * 100);
|
||||
}),
|
||||
];
|
||||
this._unsubDataEntryFlowProgress = async () => {
|
||||
(await Promise.all(unsubs)).map((unsub) => unsub());
|
||||
};
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
|
||||
Reference in New Issue
Block a user