const post = require('../lib/post') const common = require('../lib/common') module.exports = function (app) { app.post("/water/switch", async function (req, res, next) { if (req.body.switch === 1) { try { await post.postRequest('{"zoneId":[1],"setPoint": 255,"durationMinutes": 90}', 'apply_timer') const response = await post.postRequest('{}', 'poll') const water = response.updateData.zones[1].status const on = await common.heatingOn(water) let waterStatus = { "waterOn": JSON.stringify(on), } res.json(waterStatus) } catch (error) { } } else if (req.body.switch === 0) { await post.postRequest('{"zoneId":[1]}', 'cancel_timer') const response = await post.postRequest('{}', 'poll') const water = response.updateData.zones[1].status const on = await common.heatingOn(water) let waterStatus = { "waterOn": JSON.stringify(on), } res.json(waterStatus) } else { res.json({ "switch": "break" }) } }); app.post("/water/status", async function (req, res, next) { const response = await post.postRequest('{}', 'poll') const water = response.updateData.zones[1].status const on = await common.heatingOn(water) let waterStatus = { "waterOn": JSON.stringify(on), "currentSetpoint": JSON.stringify(water.currentSetpoint), "lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint), "lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes) } res.json(waterStatus) }); }