From 2e4c39b243af15105434d7568fd765794f7799a7 Mon Sep 17 00:00:00 2001 From: Jan Pecinovsky Date: Thu, 11 Oct 2018 15:20:47 +0200 Subject: [PATCH 1/5] add python gitignore --- .gitignore | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5647b9a --- /dev/null +++ b/.gitignore @@ -0,0 +1,107 @@ +# Created by .ignore support plugin (hsz.mobi) +### Python template +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + From 4649fe734d2923750b7a5ad9af16a6eb01b70505 Mon Sep 17 00:00:00 2001 From: Jan Pecinovsky Date: Thu, 11 Oct 2018 15:21:53 +0200 Subject: [PATCH 2/5] init Interface with api_key --- pyEnFace/EnphaseInterface.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyEnFace/EnphaseInterface.py b/pyEnFace/EnphaseInterface.py index bd20765..3e30a4d 100644 --- a/pyEnFace/EnphaseInterface.py +++ b/pyEnFace/EnphaseInterface.py @@ -151,7 +151,7 @@ class RawEnphaseInterface(object): def __init__(self, userId, max_wait=DEFAULT_MAX_WAIT, useragent='Mozilla/5.0', datetimeType=DateTimeType.Enphase, - errorhandler=None): + errorhandler=None, api_key=None): if errorhandler==None: errorhandler=EnphaseErrorHandler(datetimeType,max_wait) @@ -165,6 +165,9 @@ def __init__(self, userId, max_wait=DEFAULT_MAX_WAIT, self.opener.addheaders = [('User-agent',useragent)] self.apiDest = APIV2 + if api_key is not None: + APIKEYRING.append(api_key) + def _execQuery(self, system_id, command, extraParams = dict()): '''Generates a request url for the Enphase API''' From 5045971442651c236b041931741eb3220e6a0675 Mon Sep 17 00:00:00 2001 From: Jan Pecinovsky Date: Thu, 11 Oct 2018 15:50:37 +0200 Subject: [PATCH 3/5] start_date is a string, not a number --- pyEnFace/EnphaseInterface.py | 2 +- test.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test.py diff --git a/pyEnFace/EnphaseInterface.py b/pyEnFace/EnphaseInterface.py index 3e30a4d..6b86816 100644 --- a/pyEnFace/EnphaseInterface.py +++ b/pyEnFace/EnphaseInterface.py @@ -354,7 +354,7 @@ def _execQuery(self, system_id, command, extraParams = dict()): def _energy_lifetime(self,data): d = json_normalize(data, 'production',['start_date','system_id']) ts = to_timedelta(Series(d.index),unit='D') - d['start_date'] = to_datetime(d['start_date'],unit='s') + ts + d['start_date'] = to_datetime(d['start_date']) + ts d['start_date'] = d['start_date'].apply( lambda x:self.dtt.stringify('start_date',x)) d.rename(columns={0:'production'},inplace=True) diff --git a/test.py b/test.py new file mode 100644 index 0000000..a3a5c09 --- /dev/null +++ b/test.py @@ -0,0 +1,5 @@ +from pyEnFace.EnphaseInterface import PandasEnphaseInterface + +client = PandasEnphaseInterface(userId='4d7a45774e6a41320a', api_key='5965b2a3a2022ea5f2cfd7f2184bcabb') + +client.energy_lifetime(system_id=67) \ No newline at end of file From 2d1c1993177f758d05a0d77a05fedd733ba450f0 Mon Sep 17 00:00:00 2001 From: Jan Pecinovsky Date: Thu, 11 Oct 2018 15:59:05 +0200 Subject: [PATCH 4/5] Readme with basic usage --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 75bed91..89b5363 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,28 @@ # EnphaseInterface Python implementation interface to the Enphase Developer API + +## Installation + +`python3 -m pip install pyenface` + +## Usage + +```python +from pyEnFace.EnphaseInterface import PandasEnphaseInterface + +client = client = PandasEnphaseInterface(userId=, api_key=) + +# Request all systems +client.index() + +# Request inventory +client.inventory(system_id=) + +# Summary +client.summary(system_id=) + +# Get data as pandas dataframe +start = pd.Timestamp('20180101') + +client.energy_lifetime(system_id=, start_date=start) +``` \ No newline at end of file From 8c80ec173850d7c93c514f6cd8d4e48e1844702b Mon Sep 17 00:00:00 2001 From: Jan Pecinovsky Date: Thu, 11 Oct 2018 16:05:43 +0200 Subject: [PATCH 5/5] delete test file --- test.py | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 test.py diff --git a/test.py b/test.py deleted file mode 100644 index a3a5c09..0000000 --- a/test.py +++ /dev/null @@ -1,5 +0,0 @@ -from pyEnFace.EnphaseInterface import PandasEnphaseInterface - -client = PandasEnphaseInterface(userId='4d7a45774e6a41320a', api_key='5965b2a3a2022ea5f2cfd7f2184bcabb') - -client.energy_lifetime(system_id=67) \ No newline at end of file