diff --git a/index.js b/index.js index fb81d5570552bb469dfd5a4bb22a76f97696e10f..392bf9fc6c51388d7b7274b788ba83f49b2148cd 100644 --- a/index.js +++ b/index.js @@ -121,6 +121,7 @@ const endDateString = endDate.format('YYYY-MM-DD') const baseUrl = 'https://gw.prd.api.enedis.fr' const dailyDataURL = `${baseUrl}/v4/metering_data/daily_consumption` const loadCurveURL = `${baseUrl}/v4/metering_data/consumption_load_curve` +const maxPowerURL = `${baseUrl}/v4/metering_data/daily_consumption_max_power` /** * The start function is run by the BaseKonnector instance only when it got all the account @@ -170,6 +171,16 @@ async function start(fields, cozyParameters, doRetry = true) { await agregateMonthAndYearData(processedDailyData) log('info', 'Process enedis load data') await startLoadDataProcess(access_token, usage_point_id) + + log('info', 'Fetching enedis max Power data') + const fetchedMaxPowerData = await getMaxPower(access_token, usage_point_id) + log('info', 'Process enedis maxPower data') + + await processData(fetchedMaxPowerData, 'com.grandlyon.enedis.maxpower', [ + 'year', + 'month', + 'day', + ]) } catch (err) { if (err.statusCode === 403 || err.code === 403) { if (!fields.refresh_token) { @@ -227,6 +238,30 @@ async function getDailyData(token, usagePointID) { return response } +/** + * Retrieve data from the max Power endpoint + * Format: { value: "VA", "date": "YYYY-MM-DD" } + */ +async function getMaxPower(token, usagePointID) { + const dataRequest = { + method: 'GET', + uri: + maxPowerURL + + '?start=' + + startDailyDateString + + '&end=' + + endDateString + + '&usage_point_id=' + + usagePointID, + headers: { + Accept: 'application/json', + Authorization: 'Bearer ' + token, + }, + } + const response = await rp(dataRequest) + return response +} + /** * Check if history is loaded * If not, call several time the api to retrieve 1 month of history for load data