Fixing current forecast
This commit is contained in:
@@ -231,11 +231,13 @@ function summarise(slots) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function refreshForecast() {
|
||||
const sensors = await queryCurrent().catch(() => null)
|
||||
if (!sensors) return lastForecast
|
||||
const slots = await get24HourForecast(sensors).catch(() => null)
|
||||
if (!slots) return lastForecast
|
||||
lastForecast = { ts: Date.now(), slots, summary: summarise(slots) }
|
||||
export async function getForecast() {
|
||||
if(Date.now() - lastForecast.ts >= TTL) {
|
||||
const sensors = await queryCurrent().catch(() => null)
|
||||
if(!sensors) return lastForecast
|
||||
const slots = await get24HourForecast(sensors).catch(() => null)
|
||||
if(!slots) return lastForecast
|
||||
lastForecast = { ts: Date.now(), slots, summary: summarise(slots) }
|
||||
}
|
||||
return lastForecast
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user