From 5cd2d70a9b3aa53a9b21a75c1fe37c000b84cbf0 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sun, 2 Oct 2022 13:03:43 +0200 Subject: [PATCH] RPI: some more changes to properly throw and catch exceptions --- tools/rpi/hoymiles/__init__.py | 3 +++ tools/rpi/hoymiles/__main__.py | 13 ++++++++----- tools/rpi/hoymiles/outputs.py | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/rpi/hoymiles/__init__.py b/tools/rpi/hoymiles/__init__.py index ebef18af..38ca4a20 100644 --- a/tools/rpi/hoymiles/__init__.py +++ b/tools/rpi/hoymiles/__init__.py @@ -598,6 +598,9 @@ class InverterTransaction: wait = True except TimeoutError: pass + except BufferError as e: + print(f'Buffer error {e}') + pass return wait diff --git a/tools/rpi/hoymiles/__main__.py b/tools/rpi/hoymiles/__main__.py index 6ca7b98c..232270c7 100644 --- a/tools/rpi/hoymiles/__main__.py +++ b/tools/rpi/hoymiles/__main__.py @@ -86,13 +86,13 @@ def poll_inverter(inverter, do_init, retries=4): dst=inverter_ser ))) response = None - try: - while com.rxtx(): + while com.rxtx(): + try: response = com.get_payload() payload_ttl = 0 - except Exception as e_all: - print(f'Error while retrieving data: {e_all}') - pass + except Exception as e_all: + print(f'Error while retrieving data: {e_all}') + pass # Handle the response data if any if response: @@ -324,3 +324,6 @@ if __name__ == '__main__': except KeyboardInterrupt: sys.exit() + except Exception as e: + print ('Exception catched: %s' % e) + raise diff --git a/tools/rpi/hoymiles/outputs.py b/tools/rpi/hoymiles/outputs.py index a6f798ee..0e0beab4 100644 --- a/tools/rpi/hoymiles/outputs.py +++ b/tools/rpi/hoymiles/outputs.py @@ -265,7 +265,7 @@ class VzInverterOutput: r = self.session.get(url) if r.status_code != 200: raise ValueError('Could not send request (%s)' % url) - except ConnectionError as e: + except requests.exceptions.ConnectionError as e: raise ValueError('Could not send request (%s)' % e) class VolkszaehlerOutputPlugin(OutputPluginFactory): @@ -300,4 +300,7 @@ class VolkszaehlerOutputPlugin(OutputPluginFactory): serial = data["inverter_ser"] if serial in self.inverters: output = self.inverters[serial] - output.store_status(data, self.session) + try: + output.store_status(data, self.session) + except ValueError as e: + print('Could not send data to volkszaehler instance: %s' % e)