diff --git a/tests/unit/handlers/coolingSystem.handlers.test.js b/tests/unit/handlers/coolingSystem.handlers.test.js index 3b88359..71614c6 100644 --- a/tests/unit/handlers/coolingSystem.handlers.test.js +++ b/tests/unit/handlers/coolingSystem.handlers.test.js @@ -1409,6 +1409,30 @@ test('6 - differential_pressure populated when per-group PTs configured', (t) => t.pass() }) +test('6 - differential_pressure from single-transmitter array (supply/return/diff)', (t) => { + const equipment = createMockEquipment() + equipment.pressures = [ + ...equipment.pressures, + { equipment: 'PT-7502-A', value: 2.81, unit: 'bar', supply_pressure: 2.81, return_pressure: 2.2, differential_pressure: 0.61 }, + { equipment: 'PT-7502-B', value: 2.9, unit: 'bar', supply_pressure: 2.9, return_pressure: 2.3 } + ] + const config = createMockConfig() + config.cooling_system.miner_loop.line1.group_pressure_sensors = ['PT-7502-A', 'PT-7502-B'] + const view = buildMinersCircuit1View(equipment, config) + + const dp = view.lines[0].differential_pressure + t.is(dp.length, 2, 'one row per transmitter') + // Group 1: device-provided differential is preferred + t.is(dp[0].supply.tag, 'PT-7502-A', 'supply tag = transmitter id') + t.is(dp[0].return.tag, 'PT-7502-A', 'return tag = same transmitter id') + t.is(dp[0].supply.reading.value, 2.81, 'supply from supply_pressure') + t.is(dp[0].return.reading.value, 2.2, 'return from return_pressure') + t.is(dp[0].delta_p.value, 0.61, 'uses device-provided differential_pressure') + // Group 2: no device differential -> derived from supply - return + t.is(dp[1].delta_p.value, 0.6, 'derived delta-p = supply - return when DP absent') + t.pass() +}) + test('7 - rack_statuses derived from live rack power (online = power > 0)', (t) => { const equipment = createMockEquipment() const config = createMockConfig() diff --git a/workers/lib/server/handlers/cooling.system.handlers.js b/workers/lib/server/handlers/cooling.system.handlers.js index fc0d328..f26b8ec 100644 --- a/workers/lib/server/handlers/cooling.system.handlers.js +++ b/workers/lib/server/handlers/cooling.system.handlers.js @@ -76,6 +76,34 @@ function buildVibrationSwitch (vibrationSwitches, switchTag) { function buildGroupDifferentialPressure (lineConfig, pressures) { const groupSensors = lineConfig.group_pressure_sensors || {} + + if (Array.isArray(groupSensors)) { + return groupSensors.map((sensorId, i) => { + const pt = pressures?.find(s => s.equipment === sensorId) || null + const mkSlot = (val) => ({ + tag: sensorId, + type: pt?.type || null, + reading: val != null ? { value: val, unit: pt?.unit || 'bar' } : null + }) + const supply = mkSlot(pt?.supply_pressure) + const ret = mkSlot(pt?.return_pressure) + const supplyVal = supply.reading?.value + const returnVal = ret.reading?.value + const deltaPVal = pt?.differential_pressure != null + ? Math.round(pt.differential_pressure * 100) / 100 + : (supplyVal != null && returnVal != null + ? Math.round((supplyVal - returnVal) * 100) / 100 + : null) + const unit = supply.reading?.unit || ret.reading?.unit || pt?.unit || 'bar' + return { + group: i + 1, + supply, + return: ret, + delta_p: deltaPVal != null ? { value: deltaPVal, unit } : null + } + }) + } + const supplyIds = groupSensors.supply || [] const returnIds = groupSensors.return || [] const count = Math.max(supplyIds.length, returnIds.length)