2020-05-07 22:05:20 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								const post = require('../lib/post')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:47:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								const common = require('../lib/common')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-09 22:49:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								let logger = require('perfect-logger')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:05:20 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								module.exports = function (app) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:05:20 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    app.get("/heating", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /heating - START')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 21:16:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const response = await post.postRequest('{}', 'poll')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:05:20 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const heating = response.updateData.zones[0]
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /heating - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:05:20 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        res.json(heating)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    app.get("/heating/status", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /heating/status - START')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 21:16:25 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const response = await post.postRequest('{}', 'poll')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        // logger.debug(response.updateData)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const heating = response.updateData.zones[0].status
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:47:43 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const mrt = await common.updateTemp(heating)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const on = await common.heatingOn(heating)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 18:47:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const csp = await common.heatMap(heating.currentSetpoint)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        const lsp = await common.heatMap(heating.lastTimerSetPoint)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-11 16:29:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        const time = await common.convertTime(heating.nextScheduleEventUtcTime)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:41:48 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        let heatingStatus = {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 09:43:01 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            "heatingOn": JSON.stringify(on),
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:41:48 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            "measuredRoomTemp": mrt,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-08 18:47:53 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            "currentSetpoint": csp,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            "lastTimerSetPoint": lsp,
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-11 16:29:08 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								            "lastTimerDurationMinutes": JSON.stringify(heating.lastTimerDurationMinutes),
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								            "nextScheduleEventUtcTime": time
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:41:48 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        }
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /heating/status - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:41:48 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        res.json(heatingStatus)
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    app.get("/heating/config", async function (req, res, next) {
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /heating/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 heating = response.updateData.zones[0].config
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-10 21:13:16 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        logger.debug('GET - /heating/config - END')
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:12:45 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        res.json(heating)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    });
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2020-05-07 22:05:20 +01:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |