1 | export interface Logger {
|
2 | log(msg: string, ...args: any[]): void;
|
3 | error(msg: string, ...args: any[]): void;
|
4 | debug(msg: string, ...args: any[]): void;
|
5 | }
|
6 |
|
7 | export interface Build {
|
8 | chipFamily:
|
9 | | "ESP32"
|
10 | | "ESP32-C2"
|
11 | | "ESP32-C3"
|
12 | | "ESP32-C6"
|
13 | | "ESP32-H2"
|
14 | | "ESP32-S2"
|
15 | | "ESP32-S3"
|
16 | | "ESP8266";
|
17 | parts: {
|
18 | path: string;
|
19 | offset: number;
|
20 | }[];
|
21 | }
|
22 |
|
23 | export interface Manifest {
|
24 | name: string;
|
25 | version: string;
|
26 | home_assistant_domain?: string;
|
27 | funding_url?: string;
|
28 |
|
29 | new_install_skip_erase?: boolean;
|
30 | new_install_prompt_erase?: boolean;
|
31 |
|
32 | new_install_improv_wait_time?: number;
|
33 | builds: Build[];
|
34 | }
|
35 |
|
36 | export interface BaseFlashState {
|
37 | state: FlashStateType;
|
38 | message: string;
|
39 | manifest?: Manifest;
|
40 | build?: Build;
|
41 | chipFamily?: Build["chipFamily"] | "Unknown Chip";
|
42 | }
|
43 |
|
44 | export interface InitializingState extends BaseFlashState {
|
45 | state: FlashStateType.INITIALIZING;
|
46 | details: { done: boolean };
|
47 | }
|
48 |
|
49 | export interface PreparingState extends BaseFlashState {
|
50 | state: FlashStateType.PREPARING;
|
51 | details: { done: boolean };
|
52 | }
|
53 |
|
54 | export interface ErasingState extends BaseFlashState {
|
55 | state: FlashStateType.ERASING;
|
56 | details: { done: boolean };
|
57 | }
|
58 |
|
59 | export interface WritingState extends BaseFlashState {
|
60 | state: FlashStateType.WRITING;
|
61 | details: { bytesTotal: number; bytesWritten: number; percentage: number };
|
62 | }
|
63 |
|
64 | export interface FinishedState extends BaseFlashState {
|
65 | state: FlashStateType.FINISHED;
|
66 | }
|
67 |
|
68 | export interface ErrorState extends BaseFlashState {
|
69 | state: FlashStateType.ERROR;
|
70 | details: { error: FlashError; details: string | Error };
|
71 | }
|
72 |
|
73 | export type FlashState =
|
74 | | InitializingState
|
75 | | PreparingState
|
76 | | ErasingState
|
77 | | WritingState
|
78 | | FinishedState
|
79 | | ErrorState;
|
80 |
|
81 | export const enum FlashStateType {
|
82 | INITIALIZING = "initializing",
|
83 | PREPARING = "preparing",
|
84 | ERASING = "erasing",
|
85 | WRITING = "writing",
|
86 | FINISHED = "finished",
|
87 | ERROR = "error",
|
88 | }
|
89 |
|
90 | export const enum FlashError {
|
91 | FAILED_INITIALIZING = "failed_initialize",
|
92 | FAILED_MANIFEST_FETCH = "fetch_manifest_failed",
|
93 | NOT_SUPPORTED = "not_supported",
|
94 | FAILED_FIRMWARE_DOWNLOAD = "failed_firmware_download",
|
95 | WRITE_FAILED = "write_failed",
|
96 | }
|
97 |
|
98 | declare global {
|
99 | interface HTMLElementEventMap {
|
100 | "state-changed": CustomEvent<FlashState>;
|
101 | }
|
102 | }
|