This commit is contained in:
karl.hudgell 2020-05-07 22:47:43 +01:00
parent e87d27c5fb
commit 939e853ea0
2 changed files with 31 additions and 12 deletions

28
lib/common.js Normal file
View File

@ -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')
}
}
}

View File

@ -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,