Drayton_MiGenie_HASS/routes/heating_post.js
2020-05-10 21:13:16 +01:00

35 lines
1.3 KiB
JavaScript

const post = require('../lib/post')
const common = require('../lib/common')
let logger = require('perfect-logger')
module.exports = function (app) {
app.post("/heating", async function (req, res, next) {
logger.debug('POST - /heating - START')
const response = await post.postRequest('{}')
const heating = response.updateData.zones[0]
logger.debug('POST - /heating - END')
res.json(heating)
});
app.post("/heating/status", async function (req, res, next) {
logger.debug('POST - /heating/status - START')
const response = await post.postRequest('{}', 'poll')
const heating = response.updateData.zones[0].status
const mrt = await common.updateTemp(heating)
const on = await common.heatingOn(heating)
const csp = await common.heatMap(heating.currentSetpoint)
const lsp = await common.heatMap(heating.lastTimerSetPoint)
let heatingStatus = {
"heatingOn": JSON.stringify(on),
"measuredRoomTemp": mrt,
"currentSetpoint": csp,
"lastTimerSetPoint": lsp,
"lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes)
}
logger.debug('POST - /heating/status - END')
res.json(heatingStatus)
});
}