From 63b2da2f99f460491fdaa8edfb84c70c5399d97f Mon Sep 17 00:00:00 2001 From: Tim Messerschmidt Date: Mon, 11 Jan 2021 09:33:19 +0100 Subject: [PATCH] Introduces the middleware parameter to handle https://github.com/home-assistant-ecosystem/python-volkszaehler/issues/5 --- volkszaehler/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/volkszaehler/__init__.py b/volkszaehler/__init__.py index ba86079..1511e9e 100644 --- a/volkszaehler/__init__.py +++ b/volkszaehler/__init__.py @@ -9,6 +9,7 @@ _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}" @@ -26,14 +27,21 @@ def __init__( 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 = []