From ddbb35eff3d5a7b47c3518a444c25cb07ccea9dd Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 4 Sep 2022 14:24:54 +0200 Subject: [PATCH] RPI: use a requests seesion for the volkszaehler plugin to be able to use hhtp keep-alive functionality. Print debug-output only when debug is enabled --- tools/rpi/hoymiles/__main__.py | 3 ++- tools/rpi/hoymiles/outputs.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/rpi/hoymiles/__main__.py b/tools/rpi/hoymiles/__main__.py index 94fa8ff58..219b44499 100644 --- a/tools/rpi/hoymiles/__main__.py +++ b/tools/rpi/hoymiles/__main__.py @@ -72,7 +72,8 @@ def poll_inverter(inverter, retries=4): # Handle the response data if any if response: c_datetime = datetime.now() - print(f'{c_datetime} Payload: ' + hoymiles.hexify_payload(response)) + if hoymiles.HOYMILES_DEBUG_LOGGING: + print(f'{c_datetime} Payload: ' + hoymiles.hexify_payload(response)) decoder = hoymiles.ResponseDecoder(response, request=com.request, inverter_ser=inverter_ser diff --git a/tools/rpi/hoymiles/outputs.py b/tools/rpi/hoymiles/outputs.py index 0bfaecac6..a0bfdfef1 100644 --- a/tools/rpi/hoymiles/outputs.py +++ b/tools/rpi/hoymiles/outputs.py @@ -215,6 +215,7 @@ def __init__(self, config, **params): """ super().__init__(**params) + self.session = requests.Session() self.baseurl = config.get('url', 'http://localhost/middleware/') self.channels = dict() for channel in config.get('channels', []): @@ -271,7 +272,7 @@ def try_publish(self, ts, ctype, value): uid = self.channels[ctype] url = f'{self.baseurl}/data/{uid}.json?operation=add&ts={ts}&value={value}' try: - r = requests.get(url) + r = self.session.get(url) if r.status_code != 200: raise ValueError('Could not send request (%s)' % url) except ConnectionError as e: