Skip to content

Commit 80043fa

Browse files
authored
Suggest ESPHome Web in the wizard (#184)
1 parent 12546d3 commit 80043fa

File tree

3 files changed

+103
-47
lines changed

3 files changed

+103
-47
lines changed

src/install-choose/install-choose-dialog.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ class ESPHomeInstallChooseDialog extends LitElement {
116116
117117
<mwc-button
118118
no-attention
119-
slot="secondaryAction"
120-
dialogAction="close"
121-
label="Cancel"
119+
slot="primaryAction"
120+
label="Back"
121+
@click=${() => {
122+
this._state = "pick_option";
123+
}}
122124
></mwc-button>
123125
`;
124126
} else if (this._state === "web_instructions") {
@@ -160,8 +162,10 @@ class ESPHomeInstallChooseDialog extends LitElement {
160162
<mwc-button
161163
no-attention
162164
slot="secondaryAction"
163-
dialogAction="close"
164-
label="Cancel"
165+
label="Back"
166+
@click=${() => {
167+
this._state = "pick_option";
168+
}}
165169
></mwc-button>
166170
`;
167171
}

src/logs-target/logs-target-dialog.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class ESPHomeLogsTargetDialog extends LitElement {
6060
</span>
6161
${metaChevronRight}
6262
</mwc-list-item>
63+
<mwc-button
64+
no-attention
65+
slot="primaryAction"
66+
dialogAction="close"
67+
label="Cancel"
68+
></mwc-button>
6369
`;
6470
} else if (this._show === "web_instructions") {
6571
heading = "View logs in the browser";
@@ -89,11 +95,18 @@ class ESPHomeLogsTargetDialog extends LitElement {
8995
label="OPEN ESPHOME WEB"
9096
></mwc-button>
9197
</a>
98+
<mwc-button
99+
no-attention
100+
slot="secondaryAction"
101+
label="Back"
102+
@click=${() => {
103+
this._show = "options";
104+
}}
105+
></mwc-button>
92106
`;
93107
} else {
94108
heading = "Pick server port";
95-
content =
96-
this._ports === undefined
109+
content = html`${this._ports === undefined
97110
? html`
98111
<mwc-list-item>
99112
<span>Loading ports…</span>
@@ -119,7 +132,16 @@ class ESPHomeLogsTargetDialog extends LitElement {
119132
${metaChevronRight}
120133
</mwc-list-item>
121134
`
122-
);
135+
)}
136+
137+
<mwc-button
138+
no-attention
139+
slot="primaryAction"
140+
label="Back"
141+
@click=${() => {
142+
this._show = "options";
143+
}}
144+
></mwc-button>`;
123145
}
124146

125147
return html`
@@ -130,13 +152,6 @@ class ESPHomeLogsTargetDialog extends LitElement {
130152
@closed=${this._handleClose}
131153
>
132154
${content}
133-
134-
<mwc-button
135-
no-attention
136-
slot="secondaryAction"
137-
dialogAction="close"
138-
label="Cancel"
139-
></mwc-button>
140155
</mwc-dialog>
141156
`;
142157
}

src/wizard/wizard-dialog.ts

Lines changed: 69 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { openInstallChooseDialog } from "../install-choose";
3535

3636
const OK_ICON = "🎉";
3737
const WARNING_ICON = "👀";
38+
const ESPHOME_WEB_URL = "https://web.esphome.io/?dashboard_wizard";
3839

3940
/*
4041
Flow:
@@ -66,14 +67,15 @@ export class ESPHomeWizardDialog extends LitElement {
6667
@state() private _writeProgress?: number;
6768

6869
@state() private _state:
70+
| "ask_esphome_web"
6971
| "basic_config"
7072
| "connect_webserial"
7173
| "pick_board"
7274
| "connecting_webserial"
7375
| "prepare_flash"
7476
| "flashing"
7577
| "wait_come_online"
76-
| "done" = "basic_config";
78+
| "done" = supportsWebSerial ? "basic_config" : "ask_esphome_web";
7779

7880
@state() private _error?: string;
7981

@@ -88,7 +90,9 @@ export class ESPHomeWizardDialog extends LitElement {
8890
let content;
8991
let hideActions = false;
9092

91-
if (this._state === "basic_config") {
93+
if (this._state === "ask_esphome_web") {
94+
[heading, content, hideActions] = this._renderAskESPHomeWeb();
95+
} else if (this._state === "basic_config") {
9296
[heading, content, hideActions] = this._renderBasicConfig();
9397
} else if (this._state === "pick_board") {
9498
heading = "Select your ESP device";
@@ -161,41 +165,79 @@ export class ESPHomeWizardDialog extends LitElement {
161165
<div class="icon">${icon}</div>
162166
${label}
163167
</div>
164-
${showClose &&
165-
html`
168+
${showClose
169+
? html`
170+
<mwc-button
171+
slot="primaryAction"
172+
dialogAction="ok"
173+
label="Close"
174+
></mwc-button>
175+
`
176+
: ""}
177+
`;
178+
}
179+
180+
private _renderAskESPHomeWeb(): [
181+
string | undefined,
182+
TemplateResult,
183+
boolean
184+
] {
185+
const heading = "New device";
186+
let hideActions = false;
187+
const content = html`
188+
<div>
189+
A device needs to be connected to a computer using a USB cable to be
190+
added to ESPHome. Once added, ESPHome will interact with the device
191+
wirelessly.
192+
</div>
193+
<div>
194+
${allowsWebSerial
195+
? "Your browser does not support WebSerial."
196+
: "You are not browsing the dashboard over a secure connection (HTTPS)."}
197+
This prevents ESPHome from being able to install this on devices
198+
connected to this computer.
199+
</div>
200+
<div>
201+
You will still be able to install ESPHome by connecting the device to
202+
the computer that runs the ESPHome dashboard.
203+
</div>
204+
<div>
205+
Alternatively, you can use ESPHome Web to prepare a device for being
206+
used with ESPHome using this computer.
207+
</div>
208+
209+
<a
210+
slot="secondaryAction"
211+
href=${ESPHOME_WEB_URL}
212+
target="_blank"
213+
rel="noopener"
214+
>
166215
<mwc-button
167-
slot="primaryAction"
168-
dialogAction="ok"
169-
label="Close"
216+
no-attention
217+
dialogAction="close"
218+
label="Open ESPHome Web"
170219
></mwc-button>
171-
`}
220+
</a>
221+
222+
<mwc-button
223+
slot="primaryAction"
224+
label="Continue"
225+
@click=${() => {
226+
this._state = "basic_config";
227+
}}
228+
></mwc-button>
172229
`;
230+
231+
return [heading, content, hideActions];
173232
}
174233

175234
private _renderBasicConfig(): [string | undefined, TemplateResult, boolean] {
176235
if (this._hasWifiSecrets === undefined) {
177236
return [undefined, this._renderProgress("Initializing"), true];
178237
}
179-
const heading = "New device";
238+
const heading = supportsWebSerial ? "New device" : "Create configuration";
180239
let hideActions = false;
181240
const content = html`
182-
${supportsWebSerial
183-
? ""
184-
: html`
185-
<div class="notice">
186-
Limited functionality because
187-
${allowsWebSerial
188-
? html`
189-
your browser does not support WebSerial.
190-
<a
191-
href="https://esphome.io/guides/getting_started_hassio.html#webserial"
192-
target="_blank"
193-
>Learn more</a
194-
>
195-
`
196-
: "you're not browsing the dashboard over a secure connection (HTTPS)."}
197-
</div>
198-
`}
199241
${this._error ? html`<div class="error">${this._error}</div>` : ""}
200242
201243
<mwc-textfield
@@ -696,11 +738,6 @@ export class ESPHomeWizardDialog extends LitElement {
696738
line-height: 80px;
697739
color: black;
698740
}
699-
.notice {
700-
padding: 8px 24px;
701-
background-color: #fff59d;
702-
margin: 0 -24px;
703-
}
704741
.error {
705742
color: #db4437;
706743
margin-bottom: 16px;
@@ -719,7 +756,7 @@ export class ESPHomeWizardDialog extends LitElement {
719756
cursor: pointer;
720757
}
721758
722-
mwc-button[slot="secondaryAction"] {
759+
mwc-button[no-attention] {
723760
--mdc-theme-primary: #444;
724761
--mdc-theme-on-primary: white;
725762
}

0 commit comments

Comments
 (0)