1
0

const.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 ManifestState extends BaseFlashState {
  37. state: FlashStateType.MANIFEST;
  38. details: { done: boolean };
  39. }
  40. export interface PreparingState extends BaseFlashState {
  41. state: FlashStateType.PREPARING;
  42. details: { done: boolean };
  43. }
  44. export interface ErasingState extends BaseFlashState {
  45. state: FlashStateType.ERASING;
  46. details: { done: boolean };
  47. }
  48. export interface WritingState extends BaseFlashState {
  49. state: FlashStateType.WRITING;
  50. details: { bytesTotal: number; bytesWritten: number; percentage: number };
  51. }
  52. export interface FinishedState extends BaseFlashState {
  53. state: FlashStateType.FINISHED;
  54. }
  55. export interface ErrorState extends BaseFlashState {
  56. state: FlashStateType.ERROR;
  57. details: { error: FlashError; details: string | Error };
  58. }
  59. export type FlashState =
  60. | InitializingState
  61. | ManifestState
  62. | PreparingState
  63. | ErasingState
  64. | WritingState
  65. | FinishedState
  66. | ErrorState;
  67. export const enum FlashStateType {
  68. INITIALIZING = "initializing",
  69. MANIFEST = "manifest",
  70. PREPARING = "preparing",
  71. ERASING = "erasing",
  72. WRITING = "writing",
  73. FINISHED = "finished",
  74. ERROR = "error",
  75. }
  76. export const enum FlashError {
  77. FAILED_INITIALIZING = "failed_initialize",
  78. FAILED_MANIFEST_FETCH = "fetch_manifest_failed",
  79. NOT_SUPPORTED = "not_supported",
  80. FAILED_FIRMWARE_DOWNLOAD = "failed_firmware_download",
  81. WRITE_FAILED = "write_failed",
  82. }
  83. declare global {
  84. interface HTMLElementEventMap {
  85. "state-changed": CustomEvent<FlashState>;
  86. }
  87. }