50 lines
1.6 KiB
JavaScript
50 lines
1.6 KiB
JavaScript
const post = require('../lib/post')
|
|
const common = require('../lib/common')
|
|
|
|
module.exports = function (app) {
|
|
app.get("/water", async function (req, res, next) {
|
|
const response = await post.postRequest('{}', 'poll')
|
|
const water = response.updateData.zones[1]
|
|
res.json(water)
|
|
});
|
|
|
|
app.get("/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)
|
|
});
|
|
|
|
app.get("/water/config", async function (req, res, next) {
|
|
const response = await post.postRequest('{}', 'poll')
|
|
const water = response.updateData.zones[1].config
|
|
res.json(water)
|
|
});
|
|
|
|
app.get("/water/switch", async function (req, res, next) {
|
|
const response = await post.postRequest('{}', 'poll')
|
|
console.log('switch status start')
|
|
const water = response.updateData.zones[1].status
|
|
let on = await common.heatingOn(water)
|
|
if (on == true) {
|
|
on = '0'
|
|
} else {
|
|
on = '1'
|
|
}
|
|
|
|
let switchStatus = {
|
|
"switch": on
|
|
}
|
|
console.log(switchStatus)
|
|
console.log('switch status end')
|
|
res.json(switchStatus)
|
|
});
|
|
|
|
} |