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