UNPKG

2.41 kBPlain TextView Raw
1export 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
7export 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
23export interface Manifest {
24 name: string;
25 version: string;
26 home_assistant_domain?: string;
27 funding_url?: string;
28 /** @deprecated use `new_install_prompt_erase` instead */
29 new_install_skip_erase?: boolean;
30 new_install_prompt_erase?: boolean;
31 /* Time to wait to detect Improv Wi-Fi. Set to 0 to disable. */
32 new_install_improv_wait_time?: number;
33 builds: Build[];
34}
35
36export interface BaseFlashState {
37 state: FlashStateType;
38 message: string;
39 manifest?: Manifest;
40 build?: Build;
41 chipFamily?: Build["chipFamily"] | "Unknown Chip";
42}
43
44export interface InitializingState extends BaseFlashState {
45 state: FlashStateType.INITIALIZING;
46 details: { done: boolean };
47}
48
49export interface PreparingState extends BaseFlashState {
50 state: FlashStateType.PREPARING;
51 details: { done: boolean };
52}
53
54export interface ErasingState extends BaseFlashState {
55 state: FlashStateType.ERASING;
56 details: { done: boolean };
57}
58
59export interface WritingState extends BaseFlashState {
60 state: FlashStateType.WRITING;
61 details: { bytesTotal: number; bytesWritten: number; percentage: number };
62}
63
64export interface FinishedState extends BaseFlashState {
65 state: FlashStateType.FINISHED;
66}
67
68export interface ErrorState extends BaseFlashState {
69 state: FlashStateType.ERROR;
70 details: { error: FlashError; details: string | Error };
71}
72
73export type FlashState =
74 | InitializingState
75 | PreparingState
76 | ErasingState
77 | WritingState
78 | FinishedState
79 | ErrorState;
80
81export const enum FlashStateType {
82 INITIALIZING = "initializing",
83 PREPARING = "preparing",
84 ERASING = "erasing",
85 WRITING = "writing",
86 FINISHED = "finished",
87 ERROR = "error",
88}
89
90export 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
98declare global {
99 interface HTMLElementEventMap {
100 "state-changed": CustomEvent<FlashState>;
101 }
102}