Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to address Issue #14 and Issue #23 #25

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions gw2pvo/gw_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ def getDayReadings(self, date):
logging.warning(date_s + " - Received bad data " + str(data))
return result

eday_kwh = data[0]['p']
eday_kwh = 0
for day in data:
if day['d'] == date.strftime('%m/%d/%Y'):
eday_kwh = day['p']

payload = {
'id' : self.system_id,
Expand All @@ -97,18 +100,17 @@ def getDayReadings(self, date):
next_minutes = parsed_date.hour * 60 + parsed_date.minute
sample['minutes'] = next_minutes - minutes
minutes = next_minutes
eday_from_power += sample['pac'] * sample['minutes']
factor = eday_kwh / eday_from_power if eday_from_power > 0 else 1
eday_from_power += sample['pac'] * sample['minutes'] / 60 / 1000
factor = eday_kwh / eday_from_power if (eday_kwh == 0 or eday_from_power > 0) else 1

eday_kwh = 0
for sample in data['pacs']:
date += timedelta(minutes=sample['minutes'])
pgrid_w = sample['pac']
increase = pgrid_w * sample['minutes'] * factor
increase = pgrid_w * sample['minutes'] * factor / 60 / 1000
if increase > 0:
eday_kwh += increase
result['entries'].append({
'dt' : date,
'dt' : datetime.strptime(sample['date'], "%m/%d/%Y %H:%M:%S"),
'pgrid_w': pgrid_w,
'eday_kwh': round(eday_kwh, 3)
})
Expand All @@ -126,7 +128,7 @@ def call(self, url, payload):
data = r.json()
logging.debug(data)

if data['msg'] == 'success' and data['data'] is not None:
if data['msg'].lower() == 'success' and data['data'] is not None:
return data['data']
else:
loginPayload = { 'account': self.account, 'pwd': self.password }
Expand Down