From 348012cb5601cfe55bf92f6ba49963f9c1a2cc7b Mon Sep 17 00:00:00 2001 From: Parag More Date: Thu, 2 Jul 2026 18:33:17 +0530 Subject: [PATCH] fix(cooling): keep units on readings when tags are unreadable getSensorReading and getSensorWithTag now return { value: null, unit } when a configured sensor is present in the snap but its tag isn't readable (offline devices are still emitted), instead of collapsing to null and dropping the unit; they return null only when no sensor is configured. Also surface makeup pump speed/current and return it by config id so it is present with null values when offline. --- workers/lib/dcs.utils.js | 8 ++++---- .../server/handlers/cooling.system.handlers.js | 18 +++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/workers/lib/dcs.utils.js b/workers/lib/dcs.utils.js index 7b14488..da18448 100644 --- a/workers/lib/dcs.utils.js +++ b/workers/lib/dcs.utils.js @@ -35,10 +35,10 @@ function extractSiteMainMeterPowerW (dcsThing) { function getSensorReading (sensors, sensorId, defaultConfig = null) { if (!sensorId) return defaultConfig const sensor = sensors?.find(s => s.equipment === sensorId) - if (sensor?.value != null) { - return { value: sensor.value, unit: sensor.unit } - } - return defaultConfig + if (!sensor) return defaultConfig + // A configured sensor is present in the snap even when the DCS is offline; + // keep its unit and surface value: null rather than dropping the reading. + return { value: sensor.value ?? null, unit: sensor.unit ?? null } } // Like getSensorReading, but always surfaces the configured sensor id even when diff --git a/workers/lib/server/handlers/cooling.system.handlers.js b/workers/lib/server/handlers/cooling.system.handlers.js index abb0b8a..c2c417b 100644 --- a/workers/lib/server/handlers/cooling.system.handlers.js +++ b/workers/lib/server/handlers/cooling.system.handlers.js @@ -63,8 +63,10 @@ function getSensorWithTag (sensors, sensorId, defaultConfig) { return { tag: sensorId, type: sensor?.type || null, - reading: sensor?.value != null - ? { value: sensor.value, unit: sensor.unit } + // Keep the unit and surface value: null when a configured sensor is + // present but its tag isn't readable; fall back only when absent entirely. + reading: sensor + ? { value: sensor.value ?? null, unit: sensor.unit ?? null } : (defaultConfig || null) } } @@ -421,12 +423,14 @@ function buildMinersCircuit2View (equipment, config) { level: getSensorReading(levels, makeupConfig.level_sensor), level_sensor: makeupConfig.level_sensor }, - pump: makeupPump + pump: makeupPumpId ? { - id: makeupPump.equipment, - name: makeupPump.equipment, - status: makeupPump.status, - is_running: makeupPump.fbk_run_out || false, + id: makeupPumpId, + name: makeupPumpId, + status: makeupPump?.status ?? null, + is_running: makeupPump?.fbk_run_out || false, + speed: makeupPump?.speed ?? null, + current: makeupPump?.current ?? null, rated_head: makeupGlobalConfig.defaults?.pump_head || null, rated_flow: makeupGlobalConfig.defaults?.pump_flow || null }