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