From 431ddadb5f669293efd178b0f87c4ba3a35bb044 Mon Sep 17 00:00:00 2001 From: Rob Calon <31725587+robcalon@users.noreply.github.com> Date: Tue, 27 Dec 2022 17:20:24 +0100 Subject: [PATCH 1/3] asynchronous read_as_object method fix inheritance of synchronous read_as_object method from parent --- dsmr_parser/clients/serial_.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/dsmr_parser/clients/serial_.py b/dsmr_parser/clients/serial_.py index 12d2245..7adbc46 100644 --- a/dsmr_parser/clients/serial_.py +++ b/dsmr_parser/clients/serial_.py @@ -95,3 +95,32 @@ class AsyncSerialReader(SerialReader): ) except ParseError as e: logger.warning('Failed to parse telegram: %s', e) + + async def read_as_object(self, queue): + """ + Read complete DSMR telegram's from the serial interface and return a Telegram object. + + :rtype: generator + """ + + # create Serial StreamReader + conn = serial_asyncio.open_serial_connection(**self.serial_settings) + reader, _ = await conn + + while True: + + # Read line if available or give control back to loop until new + # data has arrived. + data = await reader.readline() + self.telegram_buffer.append(data.decode('ascii')) + + for telegram in self.telegram_buffer.get_all(): + + try: + queue.put_nowait( + Telegram(telegram, self.telegram_parser, self.telegram_specification) + ) + except InvalidChecksumError as e: + logger.warning(str(e)) + except ParseError as e: + logger.error('Failed to parse telegram: %s', e) From 0eae28e183699f6db2ecd8224407e6a8721766f5 Mon Sep 17 00:00:00 2001 From: Rob Calon <31725587+robcalon@users.noreply.github.com> Date: Tue, 27 Dec 2022 17:27:23 +0100 Subject: [PATCH 2/3] correct rtype --- dsmr_parser/clients/serial_.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsmr_parser/clients/serial_.py b/dsmr_parser/clients/serial_.py index 7adbc46..d8bc529 100644 --- a/dsmr_parser/clients/serial_.py +++ b/dsmr_parser/clients/serial_.py @@ -100,7 +100,7 @@ class AsyncSerialReader(SerialReader): """ Read complete DSMR telegram's from the serial interface and return a Telegram object. - :rtype: generator + :rtype: None """ # create Serial StreamReader From 371e1f3c5e079aa51b9cfe3f1e9017234e2f42fc Mon Sep 17 00:00:00 2001 From: Rob Calon <31725587+robcalon@users.noreply.github.com> Date: Tue, 27 Dec 2022 17:36:10 +0100 Subject: [PATCH 3/3] update docstring --- dsmr_parser/clients/serial_.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dsmr_parser/clients/serial_.py b/dsmr_parser/clients/serial_.py index d8bc529..f6e892f 100644 --- a/dsmr_parser/clients/serial_.py +++ b/dsmr_parser/clients/serial_.py @@ -98,7 +98,11 @@ class AsyncSerialReader(SerialReader): async def read_as_object(self, queue): """ - Read complete DSMR telegram's from the serial interface and return a Telegram object. + Read complete DSMR telegram's from the serial interface + and return a Telegram object. + + Instead of being a generator, Telegram objects are pushed + to provided queue for asynchronous processing. :rtype: None """