57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const post = require('../lib/post')
 | 
						|
const common = require('../lib/common')
 | 
						|
let logger = require('perfect-logger')
 | 
						|
 | 
						|
module.exports = function (app) {
 | 
						|
    app.get("/water", async function (req, res, next) {
 | 
						|
        logger.info('GET - /water - START')
 | 
						|
        const response = await post.postRequest('{}', 'poll')
 | 
						|
        const water = response.updateData.zones[1]
 | 
						|
        logger.info('GET - /water - END')
 | 
						|
        res.json(water)
 | 
						|
    });
 | 
						|
 | 
						|
    app.get("/water/status", async function (req, res, next) {
 | 
						|
        logger.info('GET - /water/status - START')
 | 
						|
        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)
 | 
						|
        }
 | 
						|
        logger.info('GET - /water/status - END')
 | 
						|
        res.json(waterStatus)
 | 
						|
    });
 | 
						|
 | 
						|
    app.get("/water/config", async function (req, res, next) {
 | 
						|
        logger.info('GET - /water/config - START')
 | 
						|
        const response = await post.postRequest('{}', 'poll')
 | 
						|
        const water = response.updateData.zones[1].config
 | 
						|
        logger.info('GET - /water/config - END')
 | 
						|
        res.json(water)
 | 
						|
    });
 | 
						|
 | 
						|
    app.get("/water/switch", async function (req, res, next) {
 | 
						|
        logger.info('GET - /water/switch - START')
 | 
						|
        const response = await post.postRequest('{}', 'poll')
 | 
						|
        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
 | 
						|
        }
 | 
						|
        logger.info(switchStatus)
 | 
						|
        logger.info('GET - /water/switch - END')
 | 
						|
        res.json(switchStatus)
 | 
						|
    });
 | 
						|
 | 
						|
} |