From 53c9c75ce6e094516e4246c33de46574c10461a7 Mon Sep 17 00:00:00 2001 From: Jon Hardie Date: Wed, 20 Nov 2024 10:24:10 +1300 Subject: [PATCH] - Add missing api function. (#101) --- browse-next/src/api/Device.ts | 33 ++++++++++++++++++- .../src/components/DeviceRecordingSetup.vue | 2 +- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/browse-next/src/api/Device.ts b/browse-next/src/api/Device.ts index 5ccf122c..d2274566 100644 --- a/browse-next/src/api/Device.ts +++ b/browse-next/src/api/Device.ts @@ -8,13 +8,13 @@ import type { GroupId as ProjectId, IsoFormattedDateString, LatLng, + ScheduleId, } from "@typedefs/api/common"; import type { ApiDeviceHistorySettings, ApiDeviceResponse, ApiMaskRegionsData, } from "@typedefs/api/device"; -import type { ScheduleId } from "@typedefs/api/common"; import type { DeviceConfigDetail, DeviceEvent, @@ -24,6 +24,7 @@ import type { DeviceEventType } from "@typedefs/api/consts"; import type { ApiStationResponse as ApiLocationResponse } from "@typedefs/api/station"; import type { ApiRecordingResponse } from "@typedefs/api/recording"; import type { ApiTrackResponse } from "@typedefs/api/track"; + export const createProxyDevice = ( projectNameOrId: string, deviceName: string @@ -664,3 +665,33 @@ export const getLastKnownDeviceBatteryLevel = ( }); }); }; + +export const getDeviceModel = async (deviceId: DeviceId) => { + try { + const nodegroup = await getDeviceNodeGroup(deviceId); + if (nodegroup) { + const model = nodegroup.includes("tc2") + ? "tc2" + : nodegroup.includes("pi") + ? "pi" + : null; + if (model !== null) { + return model; + } + } + return await getLatestEventsByDeviceId(deviceId, { + type: "versionData", + limit: 1, + }).then((response) => { + if (response.success && response.result.rows.length) { + return response.result.rows[0].EventDetail.details["tc2-agent"] + ? "tc2" + : "pi"; + } else { + return null; + } + }); + } catch (e) { + return null; + } +}; diff --git a/browse-next/src/components/DeviceRecordingSetup.vue b/browse-next/src/components/DeviceRecordingSetup.vue index 3f14cab6..2b2d57e0 100644 --- a/browse-next/src/components/DeviceRecordingSetup.vue +++ b/browse-next/src/components/DeviceRecordingSetup.vue @@ -667,10 +667,10 @@ watch(customRecordingWindowStop, async () => {