diff --git a/src/lib/signalr/handlers/DeviceStatus.ts b/src/lib/signalr/handlers/DeviceStatus.ts index 64270d3b..7e1cea13 100644 --- a/src/lib/signalr/handlers/DeviceStatus.ts +++ b/src/lib/signalr/handlers/DeviceStatus.ts @@ -11,11 +11,13 @@ export function handleSignalrDeviceStatus(array: unknown) { OnlineHubsStore.update((state) => { array.forEach((entry) => { + const existing = state.get(entry.device); state.set(entry.device, { hubId: entry.device, isOnline: entry.online, firmwareVersion: entry.firmwareVersion, - otaInstall: null, + otaInstall: existing?.otaInstall ?? null, + otaResult: existing?.otaResult ?? null, }); }); diff --git a/src/lib/signalr/handlers/OtaInstallFailed.ts b/src/lib/signalr/handlers/OtaInstallFailed.ts index aafd9692..2603bc34 100644 --- a/src/lib/signalr/handlers/OtaInstallFailed.ts +++ b/src/lib/signalr/handlers/OtaInstallFailed.ts @@ -21,8 +21,10 @@ export function handleSignalrOtaInstallFailed( const hub = hubs.get(hubId); if (hub && hub.otaInstall?.id === updateId) { hub.otaInstall = null; - //hub.otaError = { fatal, message }; + hub.otaResult = { success: false, message }; } return hubs; }); + + toast.error(`Hub firmware update failed: ${message}`); } diff --git a/src/lib/signalr/handlers/OtaInstallSucceeded.ts b/src/lib/signalr/handlers/OtaInstallSucceeded.ts index e58d8cc6..dcf869df 100644 --- a/src/lib/signalr/handlers/OtaInstallSucceeded.ts +++ b/src/lib/signalr/handlers/OtaInstallSucceeded.ts @@ -16,7 +16,10 @@ export function handleSignalrOtaInstallSucceeded(hubId: unknown, updateId: unkno const hub = hubs.get(hubId); if (hub && hub.otaInstall?.id === updateId) { hub.otaInstall = null; + hub.otaResult = { success: true, message: 'Update completed successfully' }; } return hubs; }); + + toast.success('Hub firmware update completed successfully!'); } diff --git a/src/lib/signalr/handlers/OtaRollback.ts b/src/lib/signalr/handlers/OtaRollback.ts index 64d9fa2d..6380e790 100644 --- a/src/lib/signalr/handlers/OtaRollback.ts +++ b/src/lib/signalr/handlers/OtaRollback.ts @@ -16,8 +16,10 @@ export function handleSignalrOtaRollback(hubId: unknown, updateId: unknown): voi const hub = hubs.get(hubId); if (hub && hub.otaInstall?.id === updateId) { hub.otaInstall = null; - //hub.otaError = { fatal: false, message: 'Rollback performed' }; + hub.otaResult = { success: false, message: 'Device rolled back to previous version' }; } return hubs; }); + + toast.warning('Hub firmware rolled back to previous version'); } diff --git a/src/lib/stores/HubsStore.ts b/src/lib/stores/HubsStore.ts index c4cfa75e..bc1caba5 100644 --- a/src/lib/stores/HubsStore.ts +++ b/src/lib/stores/HubsStore.ts @@ -15,6 +15,7 @@ export type HubOnlineState = { task: OtaUpdateProgressTask; progress: number; } | null; + otaResult: { success: boolean; message: string } | null; }; export const OwnHubsStore = writable>(new Map()); diff --git a/src/routes/(authenticated)/hubs/[hubId=guid]/update/+page.svelte b/src/routes/(authenticated)/hubs/[hubId=guid]/update/+page.svelte index 13c7b3f7..9b4df390 100644 --- a/src/routes/(authenticated)/hubs/[hubId=guid]/update/+page.svelte +++ b/src/routes/(authenticated)/hubs/[hubId=guid]/update/+page.svelte @@ -1,34 +1,192 @@ - - - Update Hub + confirmOpen, (o) => (confirmOpen = o)}> + + + Confirm Firmware Update + + Update {hubName} to version {version}? + {#if channel !== 'stable'} +

+ This version may not be from the stable channel and could contain bugs. +

+ {/if} +
+
+ + + + +
+
+ + + + Update {hubName} + Manage firmware updates for this hub. - + {#if hub} -
+ +
+ Status: {#if hub.isOnline} -

Status: Online

+ Online {:else} -

Status: Offline

+ Offline + {/if} + {#if hub.firmwareVersion} + + Firmware: {hub.firmwareVersion} + {/if} -

Firmware Version: {hub.firmwareVersion}

- + + {#if hub.otaResult} +
+ {#if hub.otaResult.success} + +
+

{hub.otaResult.message}

+
+ + +
+
+ {:else if hub.otaResult.message.includes('rolled back')} + +
+

{hub.otaResult.message}

+ +
+ {:else} + +
+

{hub.otaResult.message}

+ +
+ {/if} +
+ {/if} - + + {#if !isUpdating && !hub.otaResult} +
+
+

Firmware Channel

+ +
-

Progress

-
- Total - - Task - -
-

{hub.otaInstall?.task}

-

Flashing...

- -
-

Logs

- + + + {#if !hub.isOnline} +

Hub must be online to start an update.

+ {/if} +
+ {/if} + + + {#if isUpdating} +
+

+ Updating to {hub.otaInstall?.version}... +

+
+
+ Total + +
+
+ Task + +
+
+

{currentTaskLabel}

+
+ {/if} + + +
+
+

Update History

+ +
+ + {#if otaLogs.length === 0} +

+ No update history found for this hub. +

+ {:else} + + + + ID + Started + Status + Version + Message + + + + {#each otaLogs as otaLog (otaLog.id)} + + + {NumberToHexPadded(otaLog.id, 8)} + + + {formatRelativeTime(otaLog.startedAt)} + + + + {otaLog.status} + + + {otaLog.version} + + {otaLog.message ?? '-'} + + + {/each} + + + {/if}
- - - - ID - Started At - Status - Version - - - - {#each otaLogs as otaLog (otaLog.id)} - - - {NumberToHexPadded(otaLog.id, 8)} - - {otaLog.startedAt.toDateString()} - - {otaLog.status} - - {otaLog.version} - - {/each} - - + {:else if isLoading} +

Loading hub information...

+ {:else} +

Hub not found.

{/if}