diff --git a/manifest.konnector b/manifest.konnector index 71a45c824f7b076e497cc506c9e5e2a992caa671..127e138239e747bb56c5a088d3411b49716f6aa9 100644 --- a/manifest.konnector +++ b/manifest.konnector @@ -25,20 +25,8 @@ "accounts": { "type": "io.cozy.accounts" }, - "half hour enedis data": { - "type": "io.enedis.minute" - }, - "hourly enedis data": { - "type": "io.enedis.hour" - }, - "daily enedis data": { - "type": "io.enedis.day" - }, - "monthly enedis data": { - "type": "io.enedis.month" - }, - "yearly enedis data": { - "type": "io.enedis.year" + "enedis data": { + "type": "com.grandlyon.enedis.*" } }, "developer": { @@ -51,19 +39,7 @@ "short_description": "Récupère vos donnéees de courbe de charge depuis l'API Enedis", "long_description": "Ce connecteur récupère la courbe de charge électrique enregistrée par le compteur Linky", "permissions": { - "half hour enedis data": { - "description": "La courbe de charge électrique enregistrée par le compteur Linky" - }, - "hourly enedis data": { - "description": "La courbe de charge électrique enregistrée par le compteur Linky" - }, - "daily enedis data": { - "description": "La courbe de charge électrique enregistrée par le compteur Linky" - }, - "monthly enedis data": { - "description": "La courbe de charge électrique enregistrée par le compteur Linky" - }, - "yearly enedis data": { + "enedis data": { "description": "La courbe de charge électrique enregistrée par le compteur Linky" }, "accounts": { diff --git a/src/index.js b/src/index.js index 4346495c64ed7a963793af1016026b1f416f7c52..62c3ef926bae1e676b8283a65ea63e589047c326 100644 --- a/src/index.js +++ b/src/index.js @@ -63,7 +63,7 @@ async function start(fields, cozyParameters, doRetry = true) { log('info', 'Process enedis daily data') const processedDailyData = await processData( fetchedDailyData, - 'io.enedis.day', + 'com.grandlyon.enedis.day', ['year', 'month', 'day'] ) log('info', 'Agregate enedis daily data for month and year') @@ -75,7 +75,7 @@ async function start(fields, cozyParameters, doRetry = true) { log('info', 'Process enedis load data') const processedLoadData = await processData( fetchedLoadData, - 'io.enedis.minute', + 'com.grandlyon.enedis.minute', ['year', 'month', 'day', 'hour', 'minute'] ) log('info', 'Agregate enedis load data for hour') @@ -213,15 +213,18 @@ async function agregateMonthAndYearData(data) { // Agregation for Month data const agregatedMonthData = await buildAgregatedData( monthData, - 'io.enedis.month' + 'com.grandlyon.enedis.month' ) - await storeData(agregatedMonthData, 'io.enedis.month', ['year', 'month']) + await storeData(agregatedMonthData, 'com.grandlyon.enedis.month', [ + 'year', + 'month' + ]) // Agregation for Year data const agregatedYearData = await buildAgregatedData( yearData, - 'io.enedis.year' + 'com.grandlyon.enedis.year' ) - await storeData(agregatedYearData, 'io.enedis.year', ['year']) + await storeData(agregatedYearData, 'com.grandlyon.enedis.year', ['year']) } } @@ -248,9 +251,9 @@ async function agregateHourlyData(data) { // Agregation for Month data const agregatedMonthData = await buildAgregatedData( hourData, - 'io.enedis.hour' + 'com.grandlyon.enedis.hour' ) - await storeData(agregatedMonthData, 'io.enedis.hour', [ + await storeData(agregatedMonthData, 'com.grandlyon.enedis.hour', [ 'year', 'month', 'day', @@ -280,7 +283,9 @@ async function formateData(data, doctype) { const date = moment(record.date, 'YYYY/MM/DD h:mm:ss') if (record.value != -2) { const load = - doctype === 'io.enedis.minute' ? record.value / 2 : record.value + doctype === 'com.grandlyon.enedis.minute' + ? record.value / 2 + : record.value return { load: parseFloat(load / 1000), year: parseInt(date.format('YYYY')), @@ -316,12 +321,12 @@ async function buildAgregatedData(data, doctype) { */ async function buildDataFromKey(doctype, key, value) { let year, month, day, hour - if (doctype === 'io.enedis.year') { + if (doctype === 'com.grandlyon.enedis.year') { year = key month = 1 day = 0 hour = 0 - } else if (doctype === 'io.enedis.month') { + } else if (doctype === 'com.grandlyon.enedis.month') { const split = key.split('-') year = split[0] month = split[1] @@ -347,7 +352,7 @@ async function buildDataFromKey(doctype, key, value) { /** * Function handling special case. * The temporary aggregated data need to be remove in order for the most recent one te be saved. - * ex for io.enedis.year : + * ex for com.grandlyon.enedis.year : * { load: 76.712, year: 2020, ... } need to be replace by * { load: 82.212, year: 2020, ... } after enedis data reprocess */ @@ -358,12 +363,12 @@ async function resetInProgressAggregatedData(data, doctype) { if (result && result.length > 0) { // Filter data to remove var filtered = [] - if (doctype === 'io.enedis.year') { + if (doctype === 'com.grandlyon.enedis.year') { // Yearly case filtered = result.filter(function(el) { return el.year == data.year }) - } else if (doctype === 'io.enedis.month') { + } else if (doctype === 'com.grandlyon.enedis.month') { // Monthly case filtered = result.filter(function(el) { return el.year == data.year && el.month == data.month