From d14dfa58f2c5cd4b9f5f68e1109fd9c5a14f84cd Mon Sep 17 00:00:00 2001 From: Guilhem CARRON <gcarron@grandlyon.com> Date: Wed, 22 Dec 2021 13:16:11 +0000 Subject: [PATCH] feat(analysis): Add maxpower data endpoint and store data to enedis.maxpower doctype --- manifest.konnector | 2 +- package.json | 2 +- src/index.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/manifest.konnector b/manifest.konnector index 7b4b507..5e5628c 100644 --- a/manifest.konnector +++ b/manifest.konnector @@ -1,5 +1,5 @@ { - "version": "1.0.3", + "version": "1.1.0", "name": "Enedis", "type": "konnector", "language": "node", diff --git a/package.json b/package.json index 42cc822..8cdba5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "enedis", - "version": "1.0.3", + "version": "1.1.0", "description": "", "repository": { "type": "git", diff --git a/src/index.js b/src/index.js index b8675f5..4f0a09c 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,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 @@ -80,6 +81,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) { @@ -137,6 +148,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 -- GitLab