Skip to content

FirmwareUpdateResult

FirmwareUpdateResult = { status: "idle"; start: Promise<void>; } | { phase: FirmwareUpdatePhase; progress: number; status: "updating"; cancel: void; } | { installed: FirmwareVersions; status: "done"; reset: void; } | { status: "cancelled"; reset: void; } | { error: FirmwareError; status: "error"; reset: void; retry: Promise<void>; }

Defined in: console-sdk/src/firmware/types.ts:193

The firmware update machine as a discriminated union with variant-embedded actions (SDK_PLAN.md §3.6.7). useFirmwareUpdate returns exactly one variant; each exposes only the actions legal in its state, so the type system forbids illegal calls:

  • 'idle' — no update running. start() begins one (it rejects if no update is available or the device/provider is busy — 'command/busy'). There is no cancel to call.
  • 'updating' — in progress. phase labels the leg, progress is a weighted 0..1 fraction, and cancel() requests an orderly stop. Cancellation is not an error — it drives the machine to 'cancelled'.
  • 'done' — finished; installed reports the new versions. reset() returns the machine to 'idle'.
  • 'cancelled' — the user cancelled. Distinct from 'error' by type (never a FirmwareError). reset() returns to 'idle' so the UI can offer “resume”.
  • 'error' — the update failed with a typed FirmwareError. retry() starts a fresh attempt; reset() returns to 'idle'.

{ status: "idle"; start: Promise<void>; }

status: "idle"

No update is running.

start(): Promise<void>

Begins the update. Rejects with a FirmwareError / CommandError('command/busy') if no update is available or the BLE bus is occupied by another update or a workout.

Promise<void>


{ phase: FirmwareUpdatePhase; progress: number; status: "updating"; cancel: void; }

phase: FirmwareUpdatePhase

Which leg of the update is currently running.

progress: number

Weighted completion fraction across all phases, 0..1.

status: "updating"

An update is in progress.

cancel(): void

Requests an orderly cancel. Drives the machine to 'cancelled' — cancellation is a variant, never a rejected promise or an error.

void


{ installed: FirmwareVersions; status: "done"; reset: void; }

installed: FirmwareVersions

The versions now installed on the device.

status: "done"

The update completed successfully.

reset(): void

Returns the machine to 'idle'.

void


{ status: "cancelled"; reset: void; }

status: "cancelled"

The user cancelled the update (distinct from failure by type).

reset(): void

Returns the machine to 'idle' (the UI can offer “resume”).

void


{ error: FirmwareError; status: "error"; reset: void; retry: Promise<void>; }

error: FirmwareError

The typed failure.

status: "error"

The update failed.

reset(): void

Returns the machine to 'idle'.

void

retry(): Promise<void>

Starts a fresh update attempt.

Promise<void>