You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/* Importing Library */
var SouthernCompanyAPI = require("southern-company-api").SouthernCompanyAPI;
/* Instantiating API */
const SouthernCompany = new SouthernCompanyAPI({
username: "REDACTED",
password: "REDACTED",
accounts: ["REDACTED"],
});
/* Listening for login success */
SouthernCompany.on("connected", () => {
console.info("Connected...");
async function fetchMonthly() {
/* Getting Monthly Data */
const monthlyData = await SouthernCompany.getMonthlyData();
/* Printing Monthly Data */
console.info("Monthly Data", JSON.stringify(monthlyData));
}
fetchMonthly();
async function fetchDaily() {
/* Getting Daily Data */
const startDate = new Date(2020, 2, 1);
const endDate = new Date();
const dailyData = await SouthernCompany.getDailyData(startDate, endDate);
/* Printing daily data */
console.info("Daily Data", JSON.stringify(dailyData));
}
fetchDaily();
});
/* Listening for any errors */
SouthernCompany.on("error", console.error);
And I got the following exception:
TypeError: Cannot read properties of undefined (reading '1')
at SouthernCompanyAPI.<anonymous> (REDACTED/node_modules/southern-company-api/dist/main.js:356:48)
at Generator.next (<anonymous>)
at fulfilled (REDACTED/node_modules/southern-company-api/dist/main.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I popped into main.js and did some good 'ol console.log debugging.
{"graphset":[{"labels":[{"text":"No Bill History Available","visible":true,"font-family":"Open Sans","y":0,"x":0,"text-align":"center","font-size":"18","font-color":" #DA312A","font-weight":"300"}]}],"gui":{"behaviors":[{"id":"ShowAll","enabled":"none"},{"id":"ViewSource","enabled":"none"},{"id":"3D","enabled":"none"},{"id":"BugReport","enabled":"none"},{"id":"About","enabled":"none"},{"id":"FullScreen","enabled":"none"},{"id":"Print","enabled":"none"},{"id":"Reload","enabled":"none"},{"id":"LogScale","enabled":"none"},{"id":"SaveAsImage","enabled":"none"},{"id":"DownloadPDF","enabled":"none"},{"id":"DownloadSVG","enabled":"none"}],"context-menu[mobile]":{"button":{"visible":false,"background-color":"transparent","alpha":0,"border-radius":0},"gear":{"visible":false,"alpha":0}}}}
No series property as the code expects. The code checks for this with a if data.series != null however series is undefined here, not null. Additionally, the code is expecting 709 data points.
I was just going to fix this with a simple if series is truthy but that's not enough. What do we want to about the 708 missing data points? Do we want to throw an error if we see No Bill History Available?
Note: If I change the example code to be something slightly more reasonable it works as expected:
const endDate = new Date();
const startDate = new Date();
startDate.setDate(startDate.getDate() - 7); // 7 days
const dailyData = await SouthernCompany.getDailyData(startDate, endDate);
The text was updated successfully, but these errors were encountered:
So I ran the example in the readme:
And I got the following exception:
I popped into main.js and did some good 'ol
console.log
debugging.I added:
right before the offending line and got the following output:
I then took a look at what
graphData
had in it. Looked like:Here's what the raw graphset data looks like:
No
series
property as the code expects. The code checks for this with aif data.series != null
howeverseries
isundefined
here, not null. Additionally, the code is expecting 709 data points.I was just going to fix this with a simple
if series is truthy
but that's not enough. What do we want to about the 708 missing data points? Do we want to throw an error if we seeNo Bill History Available
?Note: If I change the example code to be something slightly more reasonable it works as expected:
The text was updated successfully, but these errors were encountered: