前端接入设备系统更新

This commit is contained in:
stu2not
2026-05-08 16:56:39 +08:00
parent 9f38965a79
commit 9a42db11cb
3 changed files with 300 additions and 1 deletions

View File

@@ -63,6 +63,22 @@ export interface DeviceRemoteSleepWakeResponse {
msg_id: string
}
export interface DeviceFirmwareStatus {
device_id: string
current_version?: string | null
latest_version?: string | null
update_available: boolean
can_update: boolean
update_status: string
progress: number
target_version?: string | null
updated_at?: string | null
}
export interface DeviceFirmwareUpdateResponse extends DeviceFirmwareStatus {
msg_id: string
}
function normalizeTimeValue(value?: string | null): string | null {
if (value === null || value === undefined) return null
const trimmed = String(value).trim()
@@ -153,6 +169,29 @@ export async function setDeviceRemoteSleepWake(
})
}
export async function getDeviceFirmwareStatus(deviceId?: string): Promise<DeviceFirmwareStatus | null> {
const resolvedDeviceId = await resolveDeviceId(deviceId)
if (!resolvedDeviceId) return null
try {
return await request<DeviceFirmwareStatus>(`/banban/devices/${resolvedDeviceId}/firmware`)
} catch (error: any) {
if (error?.status === 404) return null
throw error
}
}
export async function startDeviceFirmwareUpdate(deviceId?: string): Promise<DeviceFirmwareUpdateResponse> {
const resolvedDeviceId = await resolveDeviceId(deviceId)
if (!resolvedDeviceId) {
throw new Error('当前没有可用设备')
}
return request<DeviceFirmwareUpdateResponse>(`/banban/devices/${resolvedDeviceId}/firmware/update`, {
method: 'POST',
})
}
export async function getDeviceAlarms(
deviceId?: string,
limit = 20