From 939e853ea005a05ea4824b80f2a8d17975526550 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Thu, 7 May 2020 22:47:43 +0100 Subject: [PATCH] updates --- lib/common.js | 28 ++++++++++++++++++++++++++++ routes/heating.js | 15 +++------------ 2 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 lib/common.js diff --git a/lib/common.js b/lib/common.js new file mode 100644 index 0000000..c63678f --- /dev/null +++ b/lib/common.js @@ -0,0 +1,28 @@ + +module.exports = { + updateTemp: async (heating) => { + try { + let mrt = String(heating.measuredRoomTemp) + mrt = mrt.split(/(?=(?:..)*$)/) + mrt = parseFloat(mrt[1] + "." + mrt[0]) + return mrt + } catch (error) { + console.log('Error') + } + + }, + heatingOn: async (heating) => { + try { + let on + if (heating.currentSetpoint > 0) { + on = true + } else { + on = false + } + return on + } catch (error) { + console.log('Error') + } + + } +} \ No newline at end of file diff --git a/routes/heating.js b/routes/heating.js index cfee2dd..c6c920b 100644 --- a/routes/heating.js +++ b/routes/heating.js @@ -1,4 +1,5 @@ const post = require('../lib/post') +const common = require('../lib/common') module.exports = function (app) { app.get("/heating", async function (req, res, next) { @@ -10,18 +11,8 @@ module.exports = function (app) { app.get("/heating/status", async function (req, res, next) { const response = await post.postRequest() const heating = response.updateData.zones[0].status - - let mrt = String( heating.measuredRoomTemp ) - mrt = mrt.split( /(?=(?:..)*$)/ ) - mrt = parseFloat(mrt[1] + "." + mrt[0]) - heating.measuredRoomTemp = mrt - - let on - if (heating.currentSetpoint > 0) { - on = true - } else { - on = false - } + const mrt = await common.updateTemp(heating) + const on = await common.heatingOn(heating) let heatingStatus = { "heatingOn": on,