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

Optional middleware #6

Merged
Merged
Show file tree
Hide file tree
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
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