Browse Source

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
pull/238/head
Christian Ehrlicher 2 years ago
parent
commit
ddbb35eff3
  1. 1
      tools/rpi/hoymiles/__main__.py
  2. 3
      tools/rpi/hoymiles/outputs.py

1
tools/rpi/hoymiles/__main__.py

@ -72,6 +72,7 @@ def poll_inverter(inverter, retries=4):
# Handle the response data if any
if response:
c_datetime = datetime.now()
if hoymiles.HOYMILES_DEBUG_LOGGING:
print(f'{c_datetime} Payload: ' + hoymiles.hexify_payload(response))
decoder = hoymiles.ResponseDecoder(response,
request=com.request,

3
tools/rpi/hoymiles/outputs.py

@ -215,6 +215,7 @@ class VolkszaehlerOutputPlugin(OutputPluginFactory):
"""
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 @@ class VolkszaehlerOutputPlugin(OutputPluginFactory):
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:

Loading…
Cancel
Save