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,