CallYa Support

Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
Benny Samir Hierl 2020-10-22 11:52:22 +02:00
parent 1784e63248
commit 60deb3a402
No known key found for this signature in database
GPG key ID: 69DE3C3C097DB7F7

View file

@ -3,9 +3,12 @@
// icon-color: teal; icon-glyph: magic; // icon-color: teal; icon-glyph: magic;
/************** /**************
Version 1.0.2 Version 1.0.3
Changelog: Changelog:
v1.0.3:
- CallYa Support
- Write more useful information in the log, so that you can add support yourself if necessary
v1.0.2: v1.0.2:
- Enhanced logging for CallYa troubeshooting - Enhanced logging for CallYa troubeshooting
v1.0.1: v1.0.1:
@ -23,12 +26,16 @@ Credits:
// How many minutes should the cache be valid // How many minutes should the cache be valid
let cacheMinutes = 60; let cacheMinutes = 60;
// Please add additional values to these list, in case that your contract/tarif isn't supported by these default values.
const containerList = ['Daten', 'D_EU_DATA']
const codeList = ['-1', '45500']
////////////////////////////////////////////////////////////////////////////////
let backColor; //Widget background color let backColor; //Widget background color
let backColor2; //Widget background color let backColor2; //Widget background color
let textColor; //Widget text color let textColor; //Widget text color
let fillColor; let fillColor;
let strokeColor; let strokeColor;
let useGradient = true let useGradient = true
let widgetInputRAW = args.widgetParameter; let widgetInputRAW = args.widgetParameter;
@ -138,25 +145,39 @@ async function getUsage() {
try { try {
let res = await req.loadJSON() let res = await req.loadJSON()
console.log("unbilled-usage loaded") console.log("unbilled-usage loaded")
console.log("Try to find usageGroup 'Daten'")
let datenContainer = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup'].find(function(v){ let datenContainer = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup'].find(function(v){
return v.container == "Daten" return containerList.includes(v.container)
}) })
if (datenContainer === undefined) { if (datenContainer === undefined) {
console.log(JSON.stringify(res, null, 2)) const ErrorMsg = "Can't find usageGroup with supported Container: " + containerList.join(', ') + ".";
throw new Error("Can't find usageGroup 'Daten'") console.log(ErrorMsg)
} else {
console.log("usageGroup 'Daten' founded") const listOfContainerNamesInResponse = res['serviceUsageVBO']['usageAccounts'][0]['usageGroup'].map(function (v) {
return v.container;
})
console.log("Please check the following list to find the correct container name for your case and adjust the list of container names at the beginnging: " + listOfContainerNamesInResponse.join(", "))
throw new Error(ErrorMsg)
} }
let datenvolumen = datenContainer.usage.find(function(v){ let datenvolumen;
return v.code == "-1" if (datenContainer.usage.length == 1) {
}) datenvolumen = datenContainer.usage[0]
} else {
datenvolumen = datenContainer.usage.find(function (v) {
return codeList.includes(v.code)
})
}
if (datenvolumen === undefined) { if (datenvolumen === undefined) {
console.log("Can't find Usage with Code -1. Please check the following log to find the correct code for your case and addjust the code to 4 lines above: " + JSON.stringify(datenContainer.usage)) const ErrorMsg = "Can't find Usage with supported Codes: " + codeList.join(', ') + ".";
throw new Error("Can't find Usage with Code -1.") console.log(ErrorMsg)
const listOfCodeInResponse = datenContainer.usage.map(function(v) {
return v.code;
})
console.log("Please check the following list to find the correct code for your case and adjust the list of codes at the beginnging: " + listOfCodeInResponse.join(", "))
throw new Error(ErrorMsg)
} }
return { return {
@ -166,7 +187,6 @@ async function getUsage() {
} }
} catch (e) { } catch (e) {
console.log("Loading usage data failed") console.log("Loading usage data failed")
console.log(e)
throw e throw e
} }
}; };
@ -204,7 +224,7 @@ try {
lastUpdate = today lastUpdate = today
} }
} catch (e) { } catch (e) {
console.log(e) console.error(e)
if (cacheExists) { if (cacheExists) {
console.log("Get from Cache") console.log("Get from Cache")
data = JSON.parse(files.readString(cachePath)) data = JSON.parse(files.readString(cachePath))