const.ts 2.4 KB

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