2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const post = require('../lib/post')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 12:51:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const common = require('../lib/common')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-09 22:49:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								let logger = require('perfect-logger')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								module.exports = function (app) {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    app.get("/water", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water - START')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 21:16:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const response = await post.postRequest('{}', 'poll')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const water = response.updateData.zones[1]
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        res.json(water)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    app.get("/water/status", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water/status - START')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 21:16:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const response = await post.postRequest('{}', 'poll')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const water = response.updateData.zones[1].status
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 12:51:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const on = await common.heatingOn(water)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-11 16:29:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const time = await common.convertTime(water.nextScheduleEventUtcTime)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 12:51:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let waterStatus = {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            "waterOn": JSON.stringify(on),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            "currentSetpoint": JSON.stringify(water.currentSetpoint),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            "lastTimerSetPoint": JSON.stringify(water.lastTimerSetPoint),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-11 16:29:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            "lastTimerDurationMinutes": JSON.stringify(water.lastTimerDurationMinutes),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            "nextScheduleEventUtcTime": time
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 12:51:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water/status - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 12:51:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        res.json(waterStatus)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    app.get("/water/config", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water/config - START')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 21:16:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const response = await post.postRequest('{}', 'poll')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const water = response.updateData.zones[1].config
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water/config - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        res.json(water)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-09 21:44:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    app.get("/water/switch", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water/switch - START')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-09 21:44:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        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
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug(switchStatus)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /water/switch - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-09 21:44:21 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        res.json(switchStatus)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |