updates
This commit is contained in:
		
							parent
							
								
									e87d27c5fb
								
							
						
					
					
						commit
						939e853ea0
					
				
							
								
								
									
										28
									
								
								lib/common.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								lib/common.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = {
 | 
				
			||||||
 | 
					    updateTemp: async (heating) => {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            let mrt = String(heating.measuredRoomTemp)
 | 
				
			||||||
 | 
					            mrt = mrt.split(/(?=(?:..)*$)/)
 | 
				
			||||||
 | 
					            mrt = parseFloat(mrt[1] + "." + mrt[0])
 | 
				
			||||||
 | 
					            return mrt
 | 
				
			||||||
 | 
					        } catch (error) {
 | 
				
			||||||
 | 
					            console.log('Error')
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    heatingOn: async (heating) => {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            let on
 | 
				
			||||||
 | 
					            if (heating.currentSetpoint > 0) {
 | 
				
			||||||
 | 
					                on = true
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                on = false
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return on
 | 
				
			||||||
 | 
					        } catch (error) {
 | 
				
			||||||
 | 
					            console.log('Error')
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
const post = require('../lib/post')
 | 
					const post = require('../lib/post')
 | 
				
			||||||
 | 
					const common = require('../lib/common')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = function (app) {
 | 
					module.exports = function (app) {
 | 
				
			||||||
    app.get("/heating", async function (req, res, next) {
 | 
					    app.get("/heating", async function (req, res, next) {
 | 
				
			||||||
@ -10,18 +11,8 @@ module.exports = function (app) {
 | 
				
			|||||||
    app.get("/heating/status", async function (req, res, next) {
 | 
					    app.get("/heating/status", async function (req, res, next) {
 | 
				
			||||||
        const response = await post.postRequest()
 | 
					        const response = await post.postRequest()
 | 
				
			||||||
        const heating = response.updateData.zones[0].status
 | 
					        const heating = response.updateData.zones[0].status
 | 
				
			||||||
 | 
					        const mrt = await common.updateTemp(heating)
 | 
				
			||||||
        let mrt = String( heating.measuredRoomTemp )
 | 
					        const on = await common.heatingOn(heating)
 | 
				
			||||||
        mrt = mrt.split( /(?=(?:..)*$)/ )
 | 
					 | 
				
			||||||
        mrt = parseFloat(mrt[1] + "." + mrt[0])
 | 
					 | 
				
			||||||
        heating.measuredRoomTemp = mrt
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        let on 
 | 
					 | 
				
			||||||
        if (heating.currentSetpoint > 0) {
 | 
					 | 
				
			||||||
            on = true
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            on = false
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let heatingStatus = {
 | 
					        let heatingStatus = {
 | 
				
			||||||
            "heatingOn": on,
 | 
					            "heatingOn": on,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user