Comparing version 1.5.0 to 1.6.0
@@ -39,3 +39,3 @@ #!/usr/bin/env node | ||
} | ||
var mainHelp = "\n linky <commande> [options]\n \n Commandes:\n linky auth Cr\u00E9e une connexion \u00E0 un compte Enedis. Vous pouvez obtenir vos tokens sur https://conso.vercel.app\n linky daily R\u00E9cup\u00E8re la consommation quotidienne\n linky loadcurve R\u00E9cup\u00E8re la puissance moyenne consomm\u00E9e quotidiennement, sur un intervalle de 30 min\n linky maxpower R\u00E9cup\u00E8re la puissance maximale de consommation atteinte quotidiennement\n linky dailyprod R\u00E9cup\u00E8re la production quotidienne\n linky loadcurveprod R\u00E9cup\u00E8re la puissance moyenne produite quotidiennement, sur un intervalle de 30 min\n \n Options:\n linky auth:\n --access-token -a Access Token\n --refresh-token -r Refresh Token\n --usage-point-id -u Usage Point ID\n\n linky (daily|loadcurve|maxpower|dailyprod|loadcurveprod):\n --start -s Date de d\u00E9but (AAAA-MM-JJ). Par d\u00E9faut: hier\n --end -e Date de d\u00E9but (AAAA-MM-JJ). Par d\u00E9faut: aujourd'hui\n --usage-point-id -u Usage Point ID (PRM). Par d\u00E9faut: le dernier utilis\u00E9\n --output -o Fichier .json de sortie. Optionnel\n \n Exemples:\n linky auth -a Kft3SIZrcq -r F3AR0K8eoC -u 225169\n linky daily\n linky dailyprod --start 2022-01-01 --end 2022-01-08\n linky maxpower --start 2021-08-01 --end 2021-08-15\n linky loadcurve -s 2022-01-01 -e 2022-01-08 -o data/ma_conso.json\n linky loadcurveprod -u 225169\n"; | ||
var mainHelp = "\n linky <commande> [options]\n \n Commandes:\n linky auth Cr\u00E9e une connexion \u00E0 un compte Enedis. Vous pouvez obtenir vos tokens sur https://conso.vercel.app\n linky daily R\u00E9cup\u00E8re la consommation quotidienne\n linky loadcurve R\u00E9cup\u00E8re la puissance moyenne consomm\u00E9e quotidiennement, sur un intervalle de 30 min\n linky maxpower R\u00E9cup\u00E8re la puissance maximale de consommation atteinte quotidiennement\n linky dailyprod R\u00E9cup\u00E8re la production quotidienne\n linky loadcurveprod R\u00E9cup\u00E8re la puissance moyenne produite quotidiennement, sur un intervalle de 30 min\n \n Options:\n linky auth:\n --access-token -a Access Token\n --refresh-token -r Refresh Token\n --usage-point-id -u Usage Point ID\n\n linky (daily|loadcurve|maxpower|dailyprod|loadcurveprod):\n --start -s Date de d\u00E9but (AAAA-MM-JJ). Par d\u00E9faut: hier\n --end -e Date de d\u00E9but (AAAA-MM-JJ). Par d\u00E9faut: aujourd'hui\n --usage-point-id -u Usage Point ID (PRM). Par d\u00E9faut: le dernier utilis\u00E9\n --format -f Determine le format d'affichage de sortie du script. Options: pretty, json. Par d\u00E9faut: pretty\n --quiet -q N'affiche pas les messages et animations de progression. Optionnel\n --output -o Fichier .json de sortie. Optionnel\n \n Exemples:\n linky auth -a Kft3SIZrcq -r F3AR0K8eoC -u 225169\n linky daily\n linky dailyprod --start 2022-01-01 --end 2022-01-08\n linky maxpower --start 2021-08-01 --end 2021-08-15 --format json --quiet\n linky loadcurve -s 2022-01-01 -e 2022-01-08 -o data/ma_conso.json\n linky loadcurveprod -u 225169\n"; | ||
var authCommand = 'auth'; | ||
@@ -60,2 +60,4 @@ var dailyConsumptionCommand = 'daily'; | ||
output: { type: 'string', alias: 'o' }, | ||
format: { type: 'string', alias: 'f', default: 'pretty' }, | ||
quiet: { type: 'boolean', alias: 'q', default: false }, | ||
sandbox: { type: 'boolean' }, | ||
@@ -73,2 +75,4 @@ }, | ||
output: cli.flags.output || null, | ||
quiet: cli.flags.quiet, | ||
format: cli.flags.format, | ||
usagePointId: cli.flags.usagePointId, | ||
@@ -75,0 +79,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
export declare type Format = 'json' | 'pretty'; | ||
export declare type MeteringFlags = { | ||
@@ -5,2 +6,4 @@ start: string; | ||
output: string | null; | ||
quiet: boolean; | ||
format: Format; | ||
usagePointId?: string; | ||
@@ -7,0 +10,0 @@ }; |
@@ -71,3 +71,3 @@ "use strict"; | ||
var session = auth_1.getSession(flags.usagePointId); | ||
return handle(session.getDailyConsumption(flags.start, flags.end), 'Récupération de la consommation quotidienne', false, flags.output, flags.usagePointId); | ||
return handle(session.getDailyConsumption(flags.start, flags.end), 'Récupération de la consommation quotidienne', false, flags.output, flags.quiet, flags.format, flags.usagePointId); | ||
} | ||
@@ -77,3 +77,3 @@ exports.daily = daily; | ||
var session = auth_1.getSession(flags.usagePointId); | ||
return handle(session.getLoadCurve(flags.start, flags.end), 'Récupération de la courbe de charge', true, flags.output, flags.usagePointId); | ||
return handle(session.getLoadCurve(flags.start, flags.end), 'Récupération de la courbe de charge', true, flags.output, flags.quiet, flags.format, flags.usagePointId); | ||
} | ||
@@ -83,3 +83,3 @@ exports.loadCurve = loadCurve; | ||
var session = auth_1.getSession(flags.usagePointId); | ||
return handle(session.getDailyProduction(flags.start, flags.end), 'Récupération de la production quotidienne', false, flags.output); | ||
return handle(session.getDailyProduction(flags.start, flags.end), 'Récupération de la production quotidienne', false, flags.output, flags.quiet, flags.format); | ||
} | ||
@@ -89,3 +89,3 @@ exports.dailyProduction = dailyProduction; | ||
var session = auth_1.getSession(flags.usagePointId); | ||
return handle(session.getProductionLoadCurve(flags.start, flags.end), 'Récupération de la courbe de charge de production', true, flags.output); | ||
return handle(session.getProductionLoadCurve(flags.start, flags.end), 'Récupération de la courbe de charge de production', true, flags.output, flags.quiet, flags.format); | ||
} | ||
@@ -95,10 +95,10 @@ exports.loadCurveProduction = loadCurveProduction; | ||
var session = auth_1.getSession(flags.usagePointId); | ||
return handle(session.getMaxPower(flags.start, flags.end), 'Récupération de la puissance maximale quotidienne', true, flags.output, flags.usagePointId); | ||
return handle(session.getMaxPower(flags.start, flags.end), 'Récupération de la puissance maximale quotidienne', true, flags.output, flags.quiet, flags.format, flags.usagePointId); | ||
} | ||
exports.maxPower = maxPower; | ||
function handle(promise, spinnerText, displayTime, output, usagePointId) { | ||
function handle(promise, spinnerText, displayTime, output, quiet, format, usagePointId) { | ||
var _this = this; | ||
var session = store.getStoredSession(usagePointId); | ||
var spinner = ora_1.default().start(spinnerText); | ||
var previousAccessToken = session === null || session === void 0 ? void 0 : session.accessToken; | ||
var spinner = ora_1.default({ isSilent: quiet }).start(spinnerText); | ||
return promise | ||
@@ -118,3 +118,3 @@ .then(function (consumption) { return __awaiter(_this, void 0, void 0, function () { | ||
_b.sent(); | ||
fs_1.default.writeFileSync(output, JSON.stringify(consumption, null, 4)); | ||
fs_1.default.writeFileSync(output, JSON.stringify(consumption, null, 2)); | ||
return [3 /*break*/, 4]; | ||
@@ -127,8 +127,10 @@ case 3: | ||
if (((_a = store.getStoredSession(session === null || session === void 0 ? void 0 : session.usagePointId)) === null || _a === void 0 ? void 0 : _a.accessToken) !== previousAccessToken) { | ||
ora_1.default('Vos tokens ont été automatiquement renouvelés').succeed(); | ||
ora_1.default({ isSilent: quiet }).succeed('Vos tokens ont été automatiquement renouvelés'); | ||
} | ||
if (output) { | ||
ora_1.default("R\u00E9sultats sauvegard\u00E9s dans " + output).succeed(); | ||
ora_1.default({ isSilent: quiet }).succeed("R\u00E9sultats sauvegard\u00E9s dans " + output); | ||
} | ||
display(consumption, displayTime); | ||
if (!output) { | ||
render(format, consumption, displayTime); | ||
} | ||
return [2 /*return*/]; | ||
@@ -139,23 +141,34 @@ } | ||
.catch(function (e) { | ||
spinner.fail(e.message); | ||
spinner.stop(); | ||
ora_1.default(e.message).fail(); | ||
throw new Error(); | ||
}); | ||
} | ||
function display(consumption, displayTime) { | ||
var maxValue = Math.max.apply(Math, consumption.data.map(function (x) { return x.value; })); | ||
var chartLength = 30; | ||
// Headers | ||
console.info('\n' + | ||
chalk_1.default.yellow.underline("Date" + ' '.repeat(displayTime ? 16 : 7)) + | ||
' ' + | ||
chalk_1.default.green.underline("Valeur (" + consumption.unit + ")") + | ||
' ' + | ||
chalk_1.default.cyan.underline("Graphique" + ' '.repeat(chartLength - 9))); | ||
for (var _i = 0, _a = consumption.data; _i < _a.length; _i++) { | ||
var line = _a[_i]; | ||
console.info(chalk_1.default.yellow(line.date + " ") + | ||
chalk_1.default.green("" + line.value) + | ||
' '.repeat(10 + consumption.unit.length - line.value.toString().length) + | ||
chalk_1.default.cyan('■'.repeat(maxValue && line.value ? Math.ceil((chartLength * line.value) / maxValue) : 0))); | ||
function render(format, consumption, displayTime) { | ||
switch (format) { | ||
case 'json': | ||
console.info(JSON.stringify(consumption, null, 2)); | ||
break; | ||
case 'pretty': | ||
var maxValue = Math.max.apply(Math, consumption.data.map(function (x) { return x.value; })); | ||
var chartLength = 30; | ||
// Headers | ||
console.info('\n' + | ||
chalk_1.default.yellow.underline("Date" + ' '.repeat(displayTime ? 16 : 7)) + | ||
' ' + | ||
chalk_1.default.green.underline("Valeur (" + consumption.unit + ")") + | ||
' ' + | ||
chalk_1.default.cyan.underline("Graphique" + ' '.repeat(chartLength - 9))); | ||
// Data | ||
for (var _i = 0, _a = consumption.data; _i < _a.length; _i++) { | ||
var line = _a[_i]; | ||
console.info(chalk_1.default.yellow(line.date + " ") + | ||
chalk_1.default.green("" + line.value) + | ||
' '.repeat(10 + consumption.unit.length - line.value.toString().length) + | ||
chalk_1.default.cyan('■'.repeat(maxValue && line.value ? Math.ceil((chartLength * line.value) / maxValue) : 0))); | ||
} | ||
break; | ||
default: | ||
ora_1.default("Le format \"" + format + "\" est invalide. Formats accept\u00E9s: \"pretty\", \"json\".").fail(); | ||
} | ||
} |
{ | ||
"name": "linky", | ||
"description": "Easily retrieve your Linky power consumption", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"author": "bokub", | ||
@@ -6,0 +6,0 @@ "license": "GPL-3.0-or-later", |
@@ -35,9 +35,9 @@ "use strict"; | ||
if (retrying === void 0) { retrying = false; } | ||
return axios_1.default({ | ||
method: 'get', | ||
url: this.baseURL + "/v4/metering_data/" + endpoint + "?" + qs_1.default.stringify({ | ||
start: start, | ||
end: end, | ||
usage_point_id: this.config.usagePointId, | ||
}), | ||
var url = this.baseURL + "/v4/metering_data/" + endpoint + "?" + qs_1.default.stringify({ | ||
start: start, | ||
end: end, | ||
usage_point_id: this.config.usagePointId, | ||
}); | ||
return axios_1.default | ||
.get(url, { | ||
headers: { | ||
@@ -79,6 +79,5 @@ Authorization: "Bearer " + this.config.accessToken, | ||
var host = this.config.sandbox ? 'linky.bokub.vercel.app' : 'conso.vercel.app'; | ||
return axios_1.default({ | ||
method: 'get', | ||
url: "https://" + host + "/api/refresh?token=" + this.config.refreshToken, | ||
}) | ||
var url = "https://" + host + "/api/refresh?token=" + this.config.refreshToken; | ||
return axios_1.default | ||
.get(url) | ||
.then(function (res) { | ||
@@ -85,0 +84,0 @@ var _a = res.data.response, access_token = _a.access_token, refresh_token = _a.refresh_token; |
{ | ||
"name": "linky", | ||
"description": "Easily retrieve your Linky power consumption", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"author": "bokub", | ||
@@ -6,0 +6,0 @@ "license": "GPL-3.0-or-later", |
@@ -120,5 +120,17 @@ # Linky | ||
Pour voir l'aide détaillée : | ||
Vous pouvez changer le format d'affichage de sortie grâce à l'option `--format` | ||
```bash | ||
linky daily --start 2022-01-01 --end 2022-01-08 --format json | ||
``` | ||
Vous pouvez masquer les messages et animations de progression grâce à l'option `--quiet` | ||
```bash | ||
linky maxpower --quiet | ||
``` | ||
Pour voir l'aide détaillée et plus d'exemples : | ||
```bash | ||
linky --help | ||
@@ -125,0 +137,0 @@ ``` |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
78387
660
231