feat: add device AI role switching
This commit is contained in:
@@ -79,6 +79,23 @@ export interface DeviceFirmwareUpdateResponse extends DeviceFirmwareStatus {
|
||||
msg_id: string
|
||||
}
|
||||
|
||||
export interface DeviceRoleSummary {
|
||||
role_key: string
|
||||
name: string
|
||||
description?: string | null
|
||||
default_language?: string | null
|
||||
languages: string[]
|
||||
}
|
||||
|
||||
export interface DeviceCurrentRole {
|
||||
device_id: string
|
||||
role_key: string
|
||||
name: string
|
||||
description?: string | null
|
||||
preferred_language?: string | null
|
||||
languages: string[]
|
||||
}
|
||||
|
||||
function normalizeTimeValue(value?: string | null): string | null {
|
||||
if (value === null || value === undefined) return null
|
||||
const trimmed = String(value).trim()
|
||||
@@ -203,3 +220,40 @@ export async function getDeviceAlarms(
|
||||
|
||||
return request<DeviceAlarmListResponse>(`/banban/devices/${resolvedDeviceId}/alarms?limit=${limit}`)
|
||||
}
|
||||
|
||||
export async function getDeviceRoles(): Promise<DeviceRoleSummary[]> {
|
||||
return request<DeviceRoleSummary[]>('/banban/roles')
|
||||
}
|
||||
|
||||
export async function getDeviceRole(deviceId?: string): Promise<DeviceCurrentRole | null> {
|
||||
const resolvedDeviceId = await resolveDeviceId(deviceId)
|
||||
if (!resolvedDeviceId) return null
|
||||
|
||||
try {
|
||||
return await request<DeviceCurrentRole>(`/banban/roles/devices/${resolvedDeviceId}`)
|
||||
} catch (error: any) {
|
||||
if (error?.status === 404) return null
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateDeviceRole(
|
||||
roleKey: string,
|
||||
language?: string | null,
|
||||
deviceId?: string,
|
||||
playWelcome = false
|
||||
): Promise<DeviceCurrentRole> {
|
||||
const resolvedDeviceId = await resolveDeviceId(deviceId)
|
||||
if (!resolvedDeviceId) {
|
||||
throw new Error('当前没有可用设备')
|
||||
}
|
||||
|
||||
return request<DeviceCurrentRole>(`/banban/roles/devices/${resolvedDeviceId}`, {
|
||||
method: 'PUT',
|
||||
data: {
|
||||
role_key: roleKey,
|
||||
language: language || undefined,
|
||||
play_welcome: playWelcome,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user