Skip to content

Commit

Permalink
Add configurable index to historical requests
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Mehani <[email protected]>
  • Loading branch information
shtrom committed Aug 13, 2023
1 parent 25aa02f commit 1021685
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions AuroraPlus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,35 +47,46 @@ def gettoken(self, username, password):
except Timeout:
self.Error = 'Token request timed out'

def request(self, timespan):
def request(self, timespan, index=-1):
try:
request = self.session.get(self.url + '/usage/' + timespan +'?serviceAgreementID=' + self.serviceAgreementID + '&customerId=' + self.customerId + '&index=-1', headers={'Authorization': self.token})
request = self.session.get(
self.url
+ '/usage/'
+ timespan
+ '?serviceAgreementID='
+ self.serviceAgreementID
+ '&customerId='
+ self.customerId
+ '&index='
+ str(index),
headers={'Authorization': self.token}
)
if (request.status_code == 200):
return request.json()
else:
self.Error = 'Data request failed: ' + request.reason
self.Error = 'Data request failed: ' + request.reason
except Timeout:
self.Error = 'Data request timed out'

def getsummary(self):
summarydata = self.request("day")
def getsummary(self, index=-1):
summarydata = self.request("day", index)
self.DollarValueUsage = summarydata['SummaryTotals']['DollarValueUsage']
self.KilowattHourUsage = summarydata['SummaryTotals']['KilowattHourUsage']

def getday(self):
self.day = self.request("day")
def getday(self, index=-1):
self.day = self.request("day", index)

def getweek(self):
self.week = self.request("week")
def getweek(self, index=-1):
self.week = self.request("week", index)

def getmonth(self):
self.month = self.request("month")
def getmonth(self, index=-1):
self.month = self.request("month", index)

def getquarter(self):
self.quarter = self.request("quarter")
def getquarter(self, index=-1):
self.quarter = self.request("quarter", index)

def getyear(self):
self.year = self.request("year")
def getyear(self, index=-1):
self.year = self.request("year", index)

def getcurrent(self):
try:
Expand Down

0 comments on commit 1021685

Please sign in to comment.