From 60036e98367a7929e1ec5e376b777b850707fbb9 Mon Sep 17 00:00:00 2001 From: varun Date: Wed, 22 May 2024 07:22:19 -0400 Subject: [PATCH] automation of motor switch test2 --- src/controllers/tanksController.js | 37 +++++++++++------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 8929f0dd..2a795496 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -932,13 +932,7 @@ exports.motorAction = async (req, reply) => { const thresholdTime = moment().add(req.body.manual_threshold_time, 'minutes').toDate(); const intervalId = setInterval(async () => { // Check if threshold time has been reached - const splr_tank_info3 = await Tank.findOne({ customerId, tankName: req.body.from, tankLocation: req.body.from_type.toLowerCase() }); - const splr_tank_info3_waterlevel = parseInt(splr_tank_info3.waterlevel, 10); - const splr_tank_info3_capacity = parseInt(splr_tank_info3.capacity, 10); - const splr_tank_info3_percentage = (splr_tank_info3_waterlevel / splr_tank_info3_capacity) * 100; - console.log(splr_tank_info3_percentage,"percentage for less than 20") - - if (new Date() >= thresholdTime || splr_tank_info3_percentage<=20) { + if (new Date() >= thresholdTime) { // Stop the motor pump await Tank.updateOne( { customerId, "connections.inputConnections.motor_id": motorId }, @@ -1494,26 +1488,23 @@ exports.IotDevice = async (req, reply) => { const waterCapacityPerCm = parseInt(existingTank.waterCapacityPerCm.replace(/,/g, ''), 10); const water_level = water_level_height * waterCapacityPerCm; - if (water_level >= 0) { - existingTank.waterlevel = water_level; - - // Save the updated tank document - await existingTank.save(); - - // Update linked tanks - for (const outputConnection of existingTank.connections.outputConnections) { - const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type }); - if (linkedTank) { - for (const inputConnection of linkedTank.connections.inputConnections) { - if (inputConnection.inputConnections === tank_name) { - inputConnection.water_level = water_level; - await linkedTank.save(); - } + existingTank.waterlevel = water_level; + + // Save the updated tank document + await existingTank.save(); + + // Update linked tanks + for (const outputConnection of existingTank.connections.outputConnections) { + const linkedTank = await Tank.findOne({ customerId, tankName: outputConnection.outputConnections, tankLocation: outputConnection.output_type }); + if (linkedTank) { + for (const inputConnection of linkedTank.connections.inputConnections) { + if (inputConnection.inputConnections === tank_name) { + inputConnection.water_level = water_level; + await linkedTank.save(); } } } } - } // Send the latest three documents