Skip to content

Commit 20ff88d

Browse files
authored
Migrate to esptool.js 0.5.3 (#701)
1 parent d7a65e3 commit 20ff88d

File tree

6 files changed

+63
-26
lines changed

6 files changed

+63
-26
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@mdi/js": "^7.4.47",
4747
"@polymer/paper-tooltip": "^3.0.1",
4848
"@types/w3c-web-serial": "^1.0.7",
49-
"esptool-js": "^0.4.1",
49+
"esptool-js": "^0.5.3",
5050
"improv-wifi-serial-sdk": "^2.5.0",
5151
"lit": "^2.8.0",
5252
"tslib": "^2.8.1",

src/install-web/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { openNoPortPickedDialog } from "../no-port-picked";
22
import { createESPLoader } from "../web-serial/create-esploader";
33
import type { ESPHomeInstallWebDialog } from "./install-web-dialog";
44

5-
const preload = () => import("./install-web-dialog");
5+
export const preloadInstallWebDialog = () => import("./install-web-dialog");
66

77
export const openInstallWebDialog = async (
88
params: ESPHomeInstallWebDialog["params"],
99
// Called if a port has been picked and the dialog will be opened.
1010
onDialogOpen?: () => void,
1111
): Promise<void> => {
12-
preload();
12+
preloadInstallWebDialog();
1313

1414
let port = params.port;
1515

src/install-web/install-web-dialog.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { openCompileDialog } from "../compile";
1818
import { openInstallWebDialog } from ".";
1919
import { chipFamilyToPlatform } from "../const";
2020
import { esphomeDialogStyles } from "../styles";
21-
import { resetSerialDevice } from "../web-serial/reset-serial-device";
2221

2322
const OK_ICON = "🎉";
2423
const WARNING_ICON = "👀";
@@ -239,16 +238,21 @@ export class ESPHomeInstallWebDialog extends LitElement {
239238
return;
240239
}
241240

242-
await resetSerialDevice(esploader.transport);
241+
await esploader.hardReset();
243242
this._state = "done";
244243
} finally {
245-
if (!this.params.port) {
246-
console.log("Closing port");
247-
try {
248-
await esploader.transport.disconnect();
249-
} catch (err) {
250-
// can happen if we already closed in disconnect
244+
console.log("Closing port");
245+
try {
246+
await esploader.transport.disconnect();
247+
// If a port was passed in, we open it again
248+
if (this.params.port) {
249+
console.log("Reopening port");
250+
await this.params.port.open({
251+
baudRate: esploader.transport.baudrate,
252+
});
251253
}
254+
} catch (err) {
255+
// can happen if we already closed in disconnect
252256
}
253257
}
254258
}

web.esphome.io/src/install-adoptable/install-adoptable-dialog.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { LitElement, html } from "lit";
2-
import { customElement } from "lit/decorators.js";
1+
import { LitElement, PropertyValues, html } from "lit";
2+
import { customElement, state } from "lit/decorators.js";
33
import "@material/mwc-dialog";
44
import "@material/mwc-button";
5-
import { openInstallWebDialog } from "../../../src/install-web";
5+
import {
6+
openInstallWebDialog,
7+
preloadInstallWebDialog,
8+
} from "../../../src/install-web";
69
import { FileToFlash } from "../../../src/web-serial/flash";
710
import { esphomeDialogStyles } from "../../../src/styles";
811

@@ -18,6 +21,14 @@ const SUPPORTED_PLATFORMS = [
1821
class ESPHomeInstallAdoptableDialog extends LitElement {
1922
public port!: SerialPort;
2023

24+
@state()
25+
private _installRequested = false;
26+
27+
protected firstUpdated(changedProperties: PropertyValues): void {
28+
super.firstUpdated(changedProperties);
29+
preloadInstallWebDialog();
30+
}
31+
2132
protected render() {
2233
return html`
2334
<mwc-dialog
@@ -40,18 +51,21 @@ class ESPHomeInstallAdoptableDialog extends LitElement {
4051
slot="primaryAction"
4152
label="Install"
4253
@click=${this._handleInstall}
54+
.disabled=${this._installRequested}
4355
></mwc-button>
4456
<mwc-button
4557
no-attention
4658
slot="secondaryAction"
4759
dialogAction="close"
4860
label="Close"
61+
.disabled=${this._installRequested}
4962
></mwc-button>
5063
</mwc-dialog>
5164
`;
5265
}
5366

5467
private async _handleInstall() {
68+
this._installRequested = true;
5569
openInstallWebDialog(
5670
{
5771
port: this.port,
@@ -96,7 +110,7 @@ class ESPHomeInstallAdoptableDialog extends LitElement {
96110

97111
return [{ data, address: 0 }];
98112
},
99-
onClose(success) {
113+
async onClose(success) {
100114
if (!success) {
101115
return;
102116
}

web.esphome.io/src/install-upload/install-upload-dialog.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
1-
import { LitElement, html, css } from "lit";
2-
import { customElement, query } from "lit/decorators.js";
1+
import { LitElement, html, css, PropertyValues } from "lit";
2+
import { customElement, query, state } from "lit/decorators.js";
33
import "@material/mwc-dialog";
44
import "@material/mwc-button";
55
import "@material/mwc-icon";
6-
import { openInstallWebDialog } from "../../../src/install-web";
6+
import {
7+
openInstallWebDialog,
8+
preloadInstallWebDialog,
9+
} from "../../../src/install-web";
710
import { esphomeDialogStyles } from "../../../src/styles";
811

912
@customElement("esphome-install-upload-dialog")
1013
class ESPHomeInstallUploadDialog extends LitElement {
1114
public port!: SerialPort;
1215

16+
@state()
17+
private _installRequested = false;
18+
1319
@query("input") private _input!: HTMLInputElement;
1420

21+
protected firstUpdated(changedProperties: PropertyValues): void {
22+
super.firstUpdated(changedProperties);
23+
preloadInstallWebDialog();
24+
}
25+
1526
protected render() {
1627
return html`
1728
<mwc-dialog
@@ -22,7 +33,12 @@ class ESPHomeInstallUploadDialog extends LitElement {
2233
>
2334
<div>Select the project that you want to install on your device.</div>
2435
<div>
25-
<input type="file" accept=".bin" @change=${this._fileChanged} />
36+
<input
37+
type="file"
38+
accept=".bin"
39+
@change=${this._fileChanged}
40+
.disabled=${this._installRequested}
41+
/>
2642
</div>
2743
<div>To get the factory file of your ESPHome project:</div>
2844
<ol>
@@ -38,12 +54,14 @@ class ESPHomeInstallUploadDialog extends LitElement {
3854
slot="primaryAction"
3955
label="Install"
4056
@click=${this._handleInstall}
57+
.disabled=${this._installRequested}
4158
></mwc-button>
4259
<mwc-button
4360
no-attention
4461
slot="secondaryAction"
4562
dialogAction="close"
4663
label="Close"
64+
.disabled=${this._installRequested}
4765
></mwc-button>
4866
</mwc-dialog>
4967
`;
@@ -54,6 +72,7 @@ class ESPHomeInstallUploadDialog extends LitElement {
5472
}
5573

5674
private async _handleInstall() {
75+
this._installRequested = true;
5776
const input = this._input;
5877

5978
if (!input.files || input.files.length === 0) {

0 commit comments

Comments
 (0)