Added daytime property
This commit is contained in:
@@ -239,8 +239,3 @@ export async function refreshForecast() {
|
||||
lastForecast = { ts: Date.now(), slots, summary: summarise(slots) }
|
||||
return lastForecast
|
||||
}
|
||||
|
||||
export async function ensureForecast() {
|
||||
if (Date.now() - lastForecast.ts > TTL) await refreshForecast()
|
||||
return lastForecast
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {spec} from './spec.mjs';
|
||||
import {existsSync} from 'fs';
|
||||
import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs';
|
||||
import {getWeatherCondition} from './openweather.mjs';
|
||||
import {ensureForecast, refreshForecast} from './forecast.mjs';
|
||||
import {ensureForecast, lastForecast, refreshForecast} from './forecast.mjs';
|
||||
import {dailyWeather, hourlyWeather} from './openmeteo.mjs';
|
||||
|
||||
const app = express();
|
||||
@@ -45,15 +45,14 @@ app.get('/api/current', async (req, res) => {
|
||||
const space = getCelestialCurrent(coords.latitude, coords.longitude)
|
||||
const condition = getWeatherCondition(Object.assign(sensors, space))
|
||||
console.log(sensors);
|
||||
const { summary } = await ensureForecast()
|
||||
|
||||
// Merge forecast summary fields — sensor readings take priority
|
||||
const merged = {
|
||||
...(summary ? {
|
||||
precipitation_chance: summary.precipitation_chance,
|
||||
temperature_max: summary.temperature_max,
|
||||
temperature_min: summary.temperature_min,
|
||||
uv_index_max: summary.uv_index,
|
||||
...(lastForecast?.summary ? {
|
||||
precipitation_chance: lastForecast.summary.precipitation_chance,
|
||||
temperature_max: lastForecast.summary.temperature_max,
|
||||
temperature_min: lastForecast.summary.temperature_min,
|
||||
uv_index_max: lastForecast.summary.uv_index,
|
||||
} : {}),
|
||||
...condition,
|
||||
...sensors,
|
||||
|
||||
Reference in New Issue
Block a user