From 9e1a477feeb4cbcc82cff057fe5a9c517cc9750b Mon Sep 17 00:00:00 2001 From: Parag More Date: Thu, 2 Jul 2026 17:14:01 +0530 Subject: [PATCH] fix(cooling): keep sensor id on readings even when the tag is unreadable Single-sensor summary fields collapsed to null when the tag was not readable, dropping the sensor label. Add a sensorReading helper that returns { value, unit, sensor } whenever a sensor is configured (value null when unreadable), and null only when no sensor is set. Applied to miners C2 pre/post-HX and tower level, HVAC C2 tower level, and HVAC C1 system pressure. --- workers/lib/dcs.utils.js | 10 ++++++++ .../handlers/cooling.system.handlers.js | 25 ++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/workers/lib/dcs.utils.js b/workers/lib/dcs.utils.js index 7822b95..7b14488 100644 --- a/workers/lib/dcs.utils.js +++ b/workers/lib/dcs.utils.js @@ -41,6 +41,15 @@ function getSensorReading (sensors, sensorId, defaultConfig = null) { return defaultConfig } +// Like getSensorReading, but always surfaces the configured sensor id even when +// the tag isn't readable yet (value: null). Returns null only when no sensor is +// configured — so the UI can render the sensor label without a value. +function sensorReading (sensors, sensorId, unit = null) { + if (!sensorId) return null + const sensor = (sensors || []).find(s => s.equipment === sensorId) + return { value: sensor?.value ?? null, unit: sensor?.unit || unit, sensor: sensorId } +} + function findEquipment (equipmentList, equipmentId) { if (!equipmentId || !Array.isArray(equipmentList)) return null return equipmentList.find(e => e.equipment === equipmentId) @@ -71,6 +80,7 @@ module.exports = { extractDcsThing, extractSiteMainMeterPowerW, getSensorReading, + sensorReading, findEquipment, filterEquipmentBy, fetchDcsThing diff --git a/workers/lib/server/handlers/cooling.system.handlers.js b/workers/lib/server/handlers/cooling.system.handlers.js index 3d49722..abb0b8a 100644 --- a/workers/lib/server/handlers/cooling.system.handlers.js +++ b/workers/lib/server/handlers/cooling.system.handlers.js @@ -11,7 +11,8 @@ const { isCentralDCSEnabled, getDCSTag, extractDcsThing, - getSensorReading + getSensorReading, + sensorReading } = require('../../dcs.utils') const { aggregateRackStats } = require('./explorer.handlers') @@ -384,7 +385,6 @@ function buildMinersCircuit2View (equipment, config) { // Tower level from config sensor const towerLevelSensor = towerConfig.tower_level_sensor - const towerLevel = getSensorReading(levels, towerLevelSensor) // Cooling towers with sensor tag references const towerFanId = towerConfig.tower_fan @@ -457,14 +457,16 @@ function buildMinersCircuit2View (equipment, config) { description: towerConfig.description || viewConfig.description, water_type: towerConfig.water_type || viewConfig.water_type, summary: { - pre_hx_temp: preHxTemp != null ? { value: preHxTemp, unit: tempUnit } : null, - post_hx_temp: postHxTemp != null ? { value: postHxTemp, unit: tempUnit } : null, + pre_hx_temp: towerConfig.pre_hx_temp_sensor + ? { value: preHxTemp ?? null, unit: tempUnit || '°C', sensor: towerConfig.pre_hx_temp_sensor } + : (preHxTemp != null ? { value: preHxTemp, unit: tempUnit } : null), + post_hx_temp: towerConfig.post_hx_temp_sensor + ? { value: postHxTemp ?? null, unit: tempUnit || '°C', sensor: towerConfig.post_hx_temp_sensor } + : (postHxTemp != null ? { value: postHxTemp, unit: tempUnit } : null), delta_t: deltaT != null ? { value: deltaT, unit: tempUnit } : null, tower_capacity: towerConfig.defaults?.tower_capacity || null, tower_capacity_gcal: towerConfig.defaults?.tower_capacity_gcal || null, - tower_level: towerLevel - ? { ...towerLevel, sensor: towerLevelSensor } - : null + tower_level: sensorReading(levels, towerLevelSensor, '%') }, pumps_config: towerConfig.defaults?.pumps_config || null, heat_exchangers: heatExchangerData, @@ -731,9 +733,7 @@ function buildHvacCircuit1View (equipment, config) { delta_t: deltaT != null ? { value: deltaT, unit: tempUnit } : null, total_flow: totalFlow != null ? { value: totalFlow, unit: flowUnit } : null, rated_flow: chilledConfig.defaults?.rated_flow || null, - system_pressure: systemPressure - ? { ...systemPressure, sensor: supplyReturnConfig.pressure_sensor } - : null + system_pressure: sensorReading(pressures, supplyReturnConfig.pressure_sensor, 'bar') }, chiller: chillerData, supply_return: supplyReturn, @@ -795,7 +795,6 @@ function buildHvacCircuit2View (equipment, config) { const towerConfigRef = condenserConfig.tower || {} const towerLevelSensorId = towerConfigRef.level_sensor - const towerLevel = getSensorReading(levels, towerLevelSensorId) const towerFanId = towerConfigRef.fan const towerVibrationSwitch = buildVibrationSwitch(equipment.vibration_switches, towerConfigRef.vibration_switch) @@ -827,9 +826,7 @@ function buildHvacCircuit2View (equipment, config) { delta_t: deltaT != null ? { value: deltaT, unit: tempUnit } : null, total_flow: totalFlow != null ? { value: totalFlow, unit: flowUnit } : null, rated_flow: condenserConfig.defaults?.pumps_config?.rated_flow || null, - tower_level: towerLevel - ? { ...towerLevel, sensor: towerLevelSensorId } - : null + tower_level: sensorReading(levels, towerLevelSensorId, '%') }, pumps_config: condenserConfig.defaults?.pumps_config || null, supply_return: supplyReturn,