Ajout de données météo
This commit is contained in:
60
tools/lib/weather/config.js
Normal file
60
tools/lib/weather/config.js
Normal file
@@ -0,0 +1,60 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const DEFAULT_WEATHER_CONFIG = {
|
||||
timezone: "Europe/Paris",
|
||||
defaultHour: 12,
|
||||
defaultMinute: 0,
|
||||
windowMinutes: 60,
|
||||
precipitationThreshold: 0.1,
|
||||
providers: {
|
||||
influxdb: {
|
||||
windowMinutes: 60,
|
||||
},
|
||||
openMeteo: {
|
||||
timezone: null,
|
||||
pressureOffset: 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
function loadWeatherConfig(configPath = path.resolve(__dirname, "..", "..", "config.json")) {
|
||||
let raw = {};
|
||||
|
||||
if (fs.existsSync(configPath)) {
|
||||
try {
|
||||
raw = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
||||
} catch (error) {
|
||||
console.error(`Unable to read weather config at ${configPath}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const weather = raw.weather || {};
|
||||
|
||||
const providers = {
|
||||
...DEFAULT_WEATHER_CONFIG.providers,
|
||||
...(weather.providers || {}),
|
||||
};
|
||||
|
||||
providers.influxdb = {
|
||||
...DEFAULT_WEATHER_CONFIG.providers.influxdb,
|
||||
...(weather.providers?.influxdb || {}),
|
||||
};
|
||||
|
||||
providers.openMeteo = {
|
||||
...DEFAULT_WEATHER_CONFIG.providers.openMeteo,
|
||||
timezone: weather.providers?.openMeteo?.timezone || weather.timezone || DEFAULT_WEATHER_CONFIG.timezone,
|
||||
...(weather.providers?.openMeteo || {}),
|
||||
};
|
||||
|
||||
return {
|
||||
...DEFAULT_WEATHER_CONFIG,
|
||||
...weather,
|
||||
providers,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_WEATHER_CONFIG,
|
||||
loadWeatherConfig,
|
||||
};
|
||||
Reference in New Issue
Block a user