Skip to content

Commit

Permalink
Optional middleware (#6)
Browse files Browse the repository at this point in the history
* Formats code with black

* Introduces the middleware parameter to handle #5
  • Loading branch information
SeraphimSerapis committed Mar 10, 2021
1 parent 3d5db93 commit 4736d24
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 27 deletions.
46 changes: 23 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@

here = os.path.abspath(os.path.dirname(__file__))

with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
with open(os.path.join(here, "README.rst"), encoding="utf-8") as f:
long_description = f.read()

if sys.argv[-1] == 'publish':
os.system('python3 setup.py sdist upload')
if sys.argv[-1] == "publish":
os.system("python3 setup.py sdist upload")
sys.exit()

setup(
name='volkszaehler',
version='0.2.1',
description='Python Wrapper for interacting with the Volkszahler API.',
name="volkszaehler",
version="0.2.1",
description="Python Wrapper for interacting with the Volkszahler API.",
long_description=long_description,
url='https://github.com/home-assistant-ecosystem/python-volkszaehler',
download_url='https://github.com/home-assistant-ecosystem/python-volkszaehler/releases',
author='Fabian Affolter',
author_email='fabian@affolter-engineering.ch',
license='MIT',
install_requires=['aiohttp', 'async_timeout'],
packages=['volkszaehler'],
url="https://github.com/home-assistant-ecosystem/python-volkszaehler",
download_url="https://github.com/home-assistant-ecosystem/python-volkszaehler/releases",
author="Fabian Affolter",
author_email="fabian@affolter-engineering.ch",
license="MIT",
install_requires=["aiohttp", "async_timeout"],
packages=["volkszaehler"],
zip_safe=True,
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Utilities',
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Topic :: Utilities",
],
)
27 changes: 23 additions & 4 deletions volkszaehler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,39 @@

_LOGGER = logging.getLogger(__name__)
_RESOURCE = "{schema}://{host}:{port}/middleware.php/data/{uuid}.json"
_RESOURCE_NO_MIDDLEWARE = "{schema}://{host}:{port}/data/{uuid}.json"
_RESOURCE_FROM = "from={param_from}"
_RESOURCE_TO = "to={param_to}"


class Volkszaehler(object):
"""A class for handling the data retrieval."""

def __init__(self, loop, session, uuid, host="localhost", port=80, tls=False, param_from="", param_to=""):
def __init__(
self,
loop,
session,
uuid,
host="localhost",
port=80,
tls=False,
param_from="",
param_to="",
middleware=True,
):
"""Initialize the connection to the API."""
self._loop = loop
self._session = session
if tls:
self.url = _RESOURCE.format(schema="https", host=host, port=port, uuid=uuid)

if middleware:
self.url = _RESOURCE.format(
schema="https" if tls else "http", host=host, port=port, uuid=uuid
)
else:
self.url = _RESOURCE.format(schema="http", host=host, port=port, uuid=uuid)
self.url = _RESOURCE_NO_MIDDLEWARE.format(
schema="https" if tls else "http", host=host, port=port, uuid=uuid
)

self.data = {}
self.average = self.max = self.min = self.consumption = None
self.tuples = []
Expand Down

0 comments on commit 4736d24

Please sign in to comment.