From 305ed1b692fa3d8c3a1403d2cbe37adc470c4c64 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Tue, 12 May 2026 01:09:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(domain):=20=E4=BD=BF=E7=94=A8=E7=A9=BA?= =?UTF-8?q?=E5=80=BC=E8=A1=A8=E7=A4=BA=E7=BC=BA=E5=A4=B1=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/battery.test.ts | 10 +++++----- src/domain/battery.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/domain/battery.test.ts b/src/domain/battery.test.ts index d8f516c..687f5fd 100644 --- a/src/domain/battery.test.ts +++ b/src/domain/battery.test.ts @@ -90,9 +90,9 @@ describe('battery domain', () => { expect(snapshot.devices.every((device) => device.soh30d === null)).toBe(true) expect(snapshot.devices.every((device) => device.soh90d === null)).toBe(true) expect(snapshot.devices.every((device) => device.soh60d === null)).toBe(true) - expect(snapshot.devices.every((device) => device.cycles === 0)).toBe(true) - expect(snapshot.devices.every((device) => device.temperature === 0)).toBe(true) - expect(snapshot.devices.every((device) => device.chargeEfficiency === 0)).toBe(true) + expect(snapshot.devices.every((device) => device.cycles === null)).toBe(true) + expect(snapshot.devices.every((device) => device.temperature === null)).toBe(true) + expect(snapshot.devices.every((device) => device.chargeEfficiency === null)).toBe(true) expect(snapshot.devices[0]?.firmware).toBe('v3.8.2') expect(snapshot.devices[1]?.firmware).toBe('未提供') expect(snapshot.soh.history).toHaveLength(0) @@ -140,8 +140,8 @@ describe('battery domain', () => { expect(predicted?.cycles).toBe(6) expect(predicted?.firmware).toBe('v3.8.2') expect(predicted?.status).toBe(DEVICE_STATUS.WARNING) - expect(predicted?.temperature).toBe(0) - expect(predicted?.chargeEfficiency).toBe(0) + expect(predicted?.temperature).toBeNull() + expect(predicted?.chargeEfficiency).toBeNull() expect(snapshot.soh.history).toHaveLength(0) expect(snapshot.soh.forecast).toHaveLength(3) expect(snapshot.soh.forecast[0]).toEqual({ month: '当前', value: 60 }) diff --git a/src/domain/battery.ts b/src/domain/battery.ts index c63ed0f..9d47bc4 100644 --- a/src/domain/battery.ts +++ b/src/domain/battery.ts @@ -57,15 +57,15 @@ export const fleetUnitSchema = z.object({ displayName: z.string(), batch: z.string(), firmware: z.string(), - cycles: z.number().int(), + cycles: z.number().int().nullable(), soh: z.number().nullable(), sohSource: z.union([z.literal('prediction'), z.literal('unavailable')]), soh30d: z.number().nullable(), soh60d: z.number().nullable(), soh90d: z.number().nullable(), - temperature: z.number(), + temperature: z.number().nullable(), riskScore: z.number().int(), - chargeEfficiency: z.number(), + chargeEfficiency: z.number().nullable(), status: deviceStatusSchema, riskFactors: z.array(z.string()), }) @@ -260,8 +260,8 @@ function toFleetUnit(item: BatteryInfo, prediction?: BatteryPrediction): FleetUn const soh30d = prediction ? round1(clamp(prediction.monthSoh, 0, 100)) : null const soh90d = prediction ? round1(clamp(prediction.trmonthSoh, 0, 100)) : null const soh60d = null - const temperature = 0 - const chargeEfficiency = 0 + const temperature = null + const chargeEfficiency = null const fallbackRiskScore = (item.isLowPower || item.power <= SOH_THRESHOLDS.LOW_POWER ? 60 : 0) + (item.powerStatus === POWER_STATUS.CHARGING ? 20 : 0) @@ -272,7 +272,7 @@ function toFleetUnit(item: BatteryInfo, prediction?: BatteryPrediction): FleetUn displayName: item.devName || item.mac, batch: item.devModel, firmware: item.remark ?? '未提供', - cycles: prediction?.cyclesUsed ?? 0, + cycles: prediction?.cyclesUsed ?? null, soh, sohSource: prediction ? 'prediction' : 'unavailable', soh30d,