Correction des données météo
This commit is contained in:
@@ -90,14 +90,17 @@ function createInfluxProvider(config = {}, globalConfig = {}) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const timezone = config.timezone || globalConfig.timezone || "UTC";
|
||||
const queryApi = new InfluxDB({ url, token }).getQueryApi(org);
|
||||
const windowMinutes = config.windowMinutes ?? globalConfig.windowMinutes ?? 60;
|
||||
const precipitationThreshold = config.precipitationThreshold ?? globalConfig.precipitationThreshold ?? 0.1;
|
||||
|
||||
async function fetch({ target }) {
|
||||
const window = buildTimeWindow(target, windowMinutes);
|
||||
const targetInZone = DateTime.isDateTime(target) ? target.setZone(timezone) : DateTime.fromJSDate(target, { zone: timezone });
|
||||
const window = buildTimeWindow(targetInZone, windowMinutes);
|
||||
const weather = {};
|
||||
const contributed = new Set();
|
||||
let hasMeasurement = false;
|
||||
|
||||
for (const [key, sensor] of Object.entries(sensors)) {
|
||||
const query = buildFluxQuery(bucket, sensor, window);
|
||||
@@ -114,11 +117,28 @@ function createInfluxProvider(config = {}, globalConfig = {}) {
|
||||
|
||||
weather[key] = value;
|
||||
contributed.add("influxdb");
|
||||
hasMeasurement = true;
|
||||
} catch (error) {
|
||||
console.error(`InfluxDB error for ${key}: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasMeasurement) return null;
|
||||
|
||||
if (!hasValue(weather.illuminance) && sensors.illuminance) {
|
||||
const hour = targetInZone.hour;
|
||||
const isNight = hour < 6 || hour >= 18;
|
||||
if (isNight) {
|
||||
weather.illuminance = 0;
|
||||
contributed.add("influxdb");
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasValue(weather.precipitations) && sensors.precipitations) {
|
||||
weather.precipitations = false;
|
||||
contributed.add("influxdb");
|
||||
}
|
||||
|
||||
if (Object.keys(weather).length === 0) return null;
|
||||
|
||||
weather.source = Array.from(contributed);
|
||||
|
||||
Reference in New Issue
Block a user