From af6f5edc408f72f7db2b2a4f8973b70912dce1da Mon Sep 17 00:00:00 2001 From: Steve-Wax <52845023+Steve-Wax@users.noreply.github.com> Date: Sun, 14 Jul 2019 07:15:32 +0800 Subject: [PATCH 1/4] Update to address Issue #14 and Issue #23 See issue comments for description. --- gw2pvo/gw_api.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gw2pvo/gw_api.py b/gw2pvo/gw_api.py index e95e75c..bfb0e23 100644 --- a/gw2pvo/gw_api.py +++ b/gw2pvo/gw_api.py @@ -79,7 +79,7 @@ def getDayReadings(self, date): logging.warning(date_s + " - Received bad data " + str(data)) return result - eday_kwh = data[0]['p'] + eday_kwh = data[1]['p'] payload = { 'id' : self.system_id, @@ -97,14 +97,14 @@ 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'] + eday_from_power += sample['pac'] * sample['minutes'] / 60 / 1000 factor = eday_kwh / eday_from_power if 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({ @@ -126,7 +126,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 } From 60a11f55bfc63183a947c1692b20fd5cf3185f22 Mon Sep 17 00:00:00 2001 From: Steve-Wax <52845023+Steve-Wax@users.noreply.github.com> Date: Sun, 28 Jul 2019 06:56:00 +0800 Subject: [PATCH 2/4] Update gw_api.py --- gw2pvo/gw_api.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gw2pvo/gw_api.py b/gw2pvo/gw_api.py index bfb0e23..94cc94c 100644 --- a/gw2pvo/gw_api.py +++ b/gw2pvo/gw_api.py @@ -79,7 +79,10 @@ def getDayReadings(self, date): logging.warning(date_s + " - Received bad data " + str(data)) return result - eday_kwh = data[1]['p'] + eday_kwh = 0 + for day in data: + if day['d'] == date.strftime('%m/%d/%Y'): + eday_kwh = day['p']eday_kwh = data[1]['p'] payload = { 'id' : self.system_id, @@ -98,17 +101,16 @@ def getDayReadings(self, date): sample['minutes'] = next_minutes - minutes minutes = next_minutes eday_from_power += sample['pac'] * sample['minutes'] / 60 / 1000 - factor = eday_kwh / eday_from_power if eday_from_power > 0 else 1 + 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 / 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) }) From d68f97c2c2e2b74abe67599d2765650e5841d9a8 Mon Sep 17 00:00:00 2001 From: Steve-Wax <52845023+Steve-Wax@users.noreply.github.com> Date: Thu, 1 Aug 2019 08:04:36 +0800 Subject: [PATCH 3/4] corrected tabing and spacing problem --- gw2pvo/gw_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gw2pvo/gw_api.py b/gw2pvo/gw_api.py index 94cc94c..b10f253 100644 --- a/gw2pvo/gw_api.py +++ b/gw2pvo/gw_api.py @@ -80,8 +80,8 @@ def getDayReadings(self, date): return result eday_kwh = 0 - for day in data: - if day['d'] == date.strftime('%m/%d/%Y'): + for day in data: + if day['d'] == date.strftime('%m/%d/%Y'): eday_kwh = day['p']eday_kwh = data[1]['p'] payload = { From f4d608208fff4f26e7810ebf200e19ed076333e9 Mon Sep 17 00:00:00 2001 From: Steve-Wax <52845023+Steve-Wax@users.noreply.github.com> Date: Thu, 1 Aug 2019 09:12:48 +0800 Subject: [PATCH 4/4] Update gw_api.py --- gw2pvo/gw_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gw2pvo/gw_api.py b/gw2pvo/gw_api.py index b10f253..cd36476 100644 --- a/gw2pvo/gw_api.py +++ b/gw2pvo/gw_api.py @@ -82,7 +82,7 @@ def getDayReadings(self, date): eday_kwh = 0 for day in data: if day['d'] == date.strftime('%m/%d/%Y'): - eday_kwh = day['p']eday_kwh = data[1]['p'] + eday_kwh = day['p'] payload = { 'id' : self.system_id,