update weather every 30mins
This commit is contained in:
parent
c94bacb71e
commit
3871bf76db
14
app.js
14
app.js
@ -23,10 +23,12 @@ async function main() {
|
|||||||
case 'water':
|
case 'water':
|
||||||
console.log('Water Switch')
|
console.log('Water Switch')
|
||||||
if (globalVars.waterOn === 'true') {
|
if (globalVars.waterOn === 'true') {
|
||||||
|
globalVars.lastWaterRequest = ""
|
||||||
await common.request(0)
|
await common.request(0)
|
||||||
await common.pause(2000)
|
await common.pause(2000)
|
||||||
await menu.water()
|
await menu.water()
|
||||||
} else {
|
} else {
|
||||||
|
globalVars.lastWaterRequest = ""
|
||||||
await common.request(1)
|
await common.request(1)
|
||||||
await common.pause(2000)
|
await common.pause(2000)
|
||||||
await menu.water()
|
await menu.water()
|
||||||
@ -59,32 +61,20 @@ async function main() {
|
|||||||
switch (arr[i]) {
|
switch (arr[i]) {
|
||||||
case 'water':
|
case 'water':
|
||||||
globalVars.currentPage = arr[i]
|
globalVars.currentPage = arr[i]
|
||||||
clearInterval(globalVars.waterPolling)
|
|
||||||
clearInterval(globalVars.heatingPageSwitch)
|
|
||||||
clearInterval(globalVars.heatingPolling)
|
|
||||||
await menu.water()
|
await menu.water()
|
||||||
break;
|
break;
|
||||||
case 'mainMenu':
|
case 'mainMenu':
|
||||||
globalVars.currentPage = arr[i]
|
globalVars.currentPage = arr[i]
|
||||||
clearInterval(globalVars.waterPolling)
|
|
||||||
clearInterval(globalVars.heatingPageSwitch)
|
|
||||||
clearInterval(globalVars.heatingPolling)
|
|
||||||
led.set('off')
|
led.set('off')
|
||||||
await menu.home()
|
await menu.home()
|
||||||
break;
|
break;
|
||||||
case 'heating':
|
case 'heating':
|
||||||
globalVars.currentPage = arr[i]
|
globalVars.currentPage = arr[i]
|
||||||
clearInterval(globalVars.waterPolling)
|
|
||||||
clearInterval(globalVars.heatingPageSwitch)
|
|
||||||
clearInterval(globalVars.heatingPolling)
|
|
||||||
led.set('off')
|
led.set('off')
|
||||||
await menu.heating()
|
await menu.heating()
|
||||||
break;
|
break;
|
||||||
case 'pihole':
|
case 'pihole':
|
||||||
globalVars.currentPage = arr[i]
|
globalVars.currentPage = arr[i]
|
||||||
clearInterval(globalVars.waterPolling)
|
|
||||||
clearInterval(globalVars.heatingPageSwitch)
|
|
||||||
clearInterval(globalVars.heatingPolling)
|
|
||||||
led.set('off')
|
led.set('off')
|
||||||
await menu.piHole()
|
await menu.piHole()
|
||||||
break;
|
break;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
const got = require('got');
|
const got = require('got');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const globalVars = require('./globalVars')
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
request: async (input) => {
|
request: async (input) => {
|
||||||
@ -41,5 +43,16 @@ module.exports = {
|
|||||||
let currentDate = moment(new Date(new Date().toUTCString()))
|
let currentDate = moment(new Date(new Date().toUTCString()))
|
||||||
nextEvent = moment(nextEvent, "dddd, MMMM Do, YYYY LTS")
|
nextEvent = moment(nextEvent, "dddd, MMMM Do, YYYY LTS")
|
||||||
return currentDate.isAfter(nextEvent);
|
return currentDate.isAfter(nextEvent);
|
||||||
|
},
|
||||||
|
clearPolling: async () => {
|
||||||
|
await clearInterval(globalVars.waterPolling);
|
||||||
|
await clearInterval(globalVars.heatingPolling)
|
||||||
|
await clearInterval(globalVars.piHolePolling)
|
||||||
|
await clearInterval(globalVars.weatherPolling)
|
||||||
|
},
|
||||||
|
clearGlobalVars: async () => {
|
||||||
|
globalVars.lastHeatingRequest = ""
|
||||||
|
globalVars.lastWaterRequest = ""
|
||||||
|
globalVars.lastWeatherRequest = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,9 +6,12 @@ class globalVariables {
|
|||||||
heatingPolling = "";
|
heatingPolling = "";
|
||||||
currentPage = "";
|
currentPage = "";
|
||||||
heatingPageSwitch = "";
|
heatingPageSwitch = "";
|
||||||
heatingPageSwitchActive = "";
|
|
||||||
heatingPageS = 1;
|
heatingPageS = 1;
|
||||||
piHolePolling = "";
|
piHolePolling = "";
|
||||||
|
lastWeatherRequest = ""
|
||||||
|
lastWaterRequest = ""
|
||||||
|
lastHeatingRequest = ""
|
||||||
|
weatherPolling = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new globalVariables();
|
module.exports = new globalVariables();
|
@ -9,21 +9,22 @@ var modules = requireDir('../modules');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
home: async () => {
|
home: async () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
common.clearPolling()
|
||||||
clearInterval(globalVars.heatingPolling)
|
common.clearGlobalVars()
|
||||||
clearInterval(globalVars.piHolePolling)
|
|
||||||
await screen.clearScreen()
|
await screen.clearScreen()
|
||||||
await screen.heading('Main Menu')
|
await screen.heading('Home')
|
||||||
await screen.clearLine(2)
|
await screen.clearLine(2)
|
||||||
await screen.clearLine(3)
|
await screen.clearLine(3)
|
||||||
await screen.clearLine(4)
|
await screen.clearLine(4)
|
||||||
await screen.time()
|
await screen.time()
|
||||||
await modules.weather.getStatus()
|
await modules.weather.getStatus()
|
||||||
|
globalVars.weatherPolling = setInterval(() => {
|
||||||
|
modules.weather.getStatus()
|
||||||
|
}, 1800000);
|
||||||
},
|
},
|
||||||
water: async () => {
|
water: async () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
common.clearPolling()
|
||||||
clearInterval(globalVars.heatingPolling)
|
common.clearGlobalVars()
|
||||||
clearInterval(globalVars.piHolePolling)
|
|
||||||
await screen.clearScreen()
|
await screen.clearScreen()
|
||||||
await screen.heading('Hot Water')
|
await screen.heading('Hot Water')
|
||||||
await screen.time()
|
await screen.time()
|
||||||
@ -33,9 +34,8 @@ module.exports = {
|
|||||||
}, 60000);
|
}, 60000);
|
||||||
},
|
},
|
||||||
heating: async () => {
|
heating: async () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
common.clearPolling()
|
||||||
clearInterval(globalVars.heatingPolling)
|
common.clearGlobalVars()
|
||||||
clearInterval(globalVars.piHolePolling)
|
|
||||||
await screen.clearScreen()
|
await screen.clearScreen()
|
||||||
await screen.heading('Heating')
|
await screen.heading('Heating')
|
||||||
await screen.time()
|
await screen.time()
|
||||||
@ -45,9 +45,8 @@ module.exports = {
|
|||||||
}, 60000);
|
}, 60000);
|
||||||
},
|
},
|
||||||
piHole: async () => {
|
piHole: async () => {
|
||||||
clearInterval(globalVars.waterPolling);
|
common.clearPolling()
|
||||||
clearInterval(globalVars.heatingPolling)
|
common.clearGlobalVars()
|
||||||
clearInterval(globalVars.piHolePolling)
|
|
||||||
await screen.clearScreen()
|
await screen.clearScreen()
|
||||||
await screen.heading('PiHole')
|
await screen.heading('PiHole')
|
||||||
await screen.time()
|
await screen.time()
|
||||||
|
@ -26,35 +26,46 @@ module.exports = {
|
|||||||
// Once we're done streaming the response, parse it as json.
|
// Once we're done streaming the response, parse it as json.
|
||||||
response.on('end', async function () {
|
response.on('end', async function () {
|
||||||
var data = JSON.parse(content);
|
var data = JSON.parse(content);
|
||||||
let waterOn = data.waterOn
|
let waterdata = {
|
||||||
|
"waterOn": data.waterOn,
|
||||||
var time = await common.nextEvent(data.nextScheduleEventUtcTime)
|
"time": await common.nextEvent(data.nextScheduleEventUtcTime),
|
||||||
|
}
|
||||||
globalVars.waterNextEvent = time
|
globalVars.waterNextEvent = waterdata.time
|
||||||
|
|
||||||
let m = await common.time(data.nextScheduleEventUtcTime)
|
|
||||||
|
|
||||||
|
// let m = await common.time(data.nextScheduleEventUtcTime)
|
||||||
|
async function updateWater() {
|
||||||
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
if (globalVars.waterOn === "" || globalVars.waterOn === "error") {
|
||||||
if (waterOn === 'true') {
|
if (waterdata.waterOn === 'true') {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterdata.waterOn
|
||||||
lcd.waterPageOne('Heating', globalVars.waterNextEvent)
|
lcd.waterPageOne('Heating', globalVars.waterNextEvent)
|
||||||
led.set('red')
|
led.set('red')
|
||||||
} else {
|
} else {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterdata.waterOn
|
||||||
lcd.waterPageOne('Not Heating', globalVars.waterNextEvent)
|
lcd.waterPageOne('Not Heating', globalVars.waterNextEvent)
|
||||||
led.set('blue')
|
led.set('blue')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (waterOn === 'true') {
|
if (waterdata.waterOn === 'true') {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterdata.waterOn
|
||||||
lcd.waterPageOne('Heating', globalVars.waterNextEvent)
|
lcd.waterPageOne('Heating', globalVars.waterNextEvent)
|
||||||
led.set('red')
|
led.set('red')
|
||||||
} else {
|
} else {
|
||||||
globalVars.waterOn = waterOn
|
globalVars.waterOn = waterdata.waterOn
|
||||||
lcd.waterPageOne('Not Heating', globalVars.waterNextEvent)
|
lcd.waterPageOne('Not Heating', globalVars.waterNextEvent)
|
||||||
led.set('blue')
|
led.set('blue')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (globalVars.lastWaterRequest === "") {
|
||||||
|
console.log('initial load')
|
||||||
|
globalVars.lastWaterRequest = waterdata
|
||||||
|
updateWater()
|
||||||
|
} else if (globalVars.lastWaterRequest = waterdata) {
|
||||||
|
console.log('no update')
|
||||||
|
} else {
|
||||||
|
updateWater()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -29,14 +29,27 @@ module.exports = {
|
|||||||
// Once we're done streaming the response, parse it as json.
|
// Once we're done streaming the response, parse it as json.
|
||||||
response.on('end', async function () {
|
response.on('end', async function () {
|
||||||
var data = JSON.parse(content);
|
var data = JSON.parse(content);
|
||||||
let city = data.name
|
let weatherData = {
|
||||||
let weatherDescription = data.weather[0].description
|
"city": data.name,
|
||||||
let currentTemp = Math.floor(data.main.temp)
|
"weatherDescription": data.weather[0].description,
|
||||||
let highTemp = Math.floor(data.main.temp_max)
|
"currentTemp": Math.floor(data.main.temp),
|
||||||
let lowTemp = Math.floor(data.main.temp_min)
|
"highTemp": Math.floor(data.main.temp_max),
|
||||||
|
"lowTemp": Math.floor(data.main.temp_min)
|
||||||
await lcd.weather(city, weatherDescription, currentTemp, highTemp, lowTemp)
|
}
|
||||||
|
async function updateWeather() {
|
||||||
|
console.log('weather updated')
|
||||||
|
globalVars.lastWeatherRequest = weatherData
|
||||||
|
await lcd.weather(weatherData.city, weatherData.weatherDescription, weatherData.currentTemp, weatherData.highTemp, weatherData.lowTemp)
|
||||||
|
}
|
||||||
|
if (globalVars.lastWeatherRequest === "") {
|
||||||
|
console.log('initial load')
|
||||||
|
globalVars.lastWeatherRequest = weatherData
|
||||||
|
updateWeather()
|
||||||
|
} else if (globalVars.lastWeatherRequest = weatherData) {
|
||||||
|
console.log('no update')
|
||||||
|
} else {
|
||||||
|
updateWeather()
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
// Report errors
|
// Report errors
|
||||||
|
Loading…
x
Reference in New Issue
Block a user