mirror of
https://github.com/esphome/esp-web-tools.git
synced 2025-07-26 21:26:42 +00:00
Allow specifying checkFirmware override (#216)
This commit is contained in:
parent
22c0a1a1cb
commit
95b8efa500
22
index.html
22
index.html
@ -403,6 +403,28 @@
|
||||
is visible in the ESP Web Tools menu when connected to a device running
|
||||
your firmware (as detected via Improv).
|
||||
</p>
|
||||
<p>
|
||||
ESP Web Tools allows you to provide your own check if the device is
|
||||
running the same firmware as specified in the manifest. This check can
|
||||
be setting the <code>overrides</code> property on
|
||||
<code><esp-web-install-button></code>. The value is an object
|
||||
containing a
|
||||
<code>checkSameFirmwareVersion(manifest, improvInfo)</code> function.
|
||||
The <code>manifest</code> parameter is your manifest and
|
||||
<code>improvInfo</code> is the information returned from Improv:
|
||||
<code>{ name, firmware, version, chipFamily }</code>. This check is only
|
||||
called if the device firmware was detected via Improv.
|
||||
</p>
|
||||
<pre>
|
||||
const button = document.querySelector('esp-web-install-button');
|
||||
button.overrides = {
|
||||
checkSameFirmwareVersion(manifest, improvInfo) {
|
||||
const manifestFirmware = manifest.name.toLowerCase();
|
||||
const deviceFirmware = improvInfo.firmware.toLowerCase();
|
||||
return manifestFirmware.includes(deviceFirmware);
|
||||
}
|
||||
};</pre
|
||||
>
|
||||
|
||||
<h3 id="customize">Customizing the look and feel</h3>
|
||||
<p>
|
||||
|
@ -30,6 +30,7 @@ export const connect = async (button: InstallButton) => {
|
||||
const el = document.createElement("ewt-install-dialog");
|
||||
el.port = port;
|
||||
el.manifestPath = button.manifest || button.getAttribute("manifest")!;
|
||||
el.overrides = button.overrides;
|
||||
el.addEventListener(
|
||||
"closed",
|
||||
() => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { FlashState } from "./const";
|
||||
import type { FlashState } from "./const";
|
||||
import type { EwtInstallDialog } from "./install-dialog";
|
||||
|
||||
export class InstallButton extends HTMLElement {
|
||||
public static isSupported = "serial" in navigator;
|
||||
@ -71,6 +72,8 @@ export class InstallButton extends HTMLElement {
|
||||
|
||||
public renderRoot?: ShadowRoot;
|
||||
|
||||
public overrides: EwtInstallDialog["overrides"];
|
||||
|
||||
public static preload() {
|
||||
import("./connect");
|
||||
}
|
||||
|
@ -30,13 +30,20 @@ import { dialogStyles } from "./styles";
|
||||
const ERROR_ICON = "⚠️";
|
||||
const OK_ICON = "🎉";
|
||||
|
||||
class EwtInstallDialog extends LitElement {
|
||||
export class EwtInstallDialog extends LitElement {
|
||||
public port!: SerialPort;
|
||||
|
||||
public manifestPath!: string;
|
||||
|
||||
public logger: Logger = console;
|
||||
|
||||
public overrides?: {
|
||||
checkSameFirmwareVersion?: (
|
||||
manifest: Manifest,
|
||||
deviceImprov: ImprovSerial["info"]
|
||||
) => boolean;
|
||||
};
|
||||
|
||||
private _manifest!: Manifest;
|
||||
|
||||
private _info?: ImprovSerial["info"];
|
||||
@ -877,7 +884,11 @@ class EwtInstallDialog extends LitElement {
|
||||
* Return if the device runs same firmware as manifest.
|
||||
*/
|
||||
private get _isSameFirmware() {
|
||||
return this._info?.firmware === this._manifest!.name;
|
||||
return !this._info
|
||||
? false
|
||||
: this.overrides?.checkSameFirmwareVersion
|
||||
? this.overrides.checkSameFirmwareVersion(this._manifest, this._info)
|
||||
: this._info.firmware === this._manifest.name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user