const.ts 2.3 KB

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