From 911162fca2eac07297757198fae9b92f78e40803 Mon Sep 17 00:00:00 2001 From: Gwendal Raoul Date: Mon, 24 Apr 2023 11:27:12 +0200 Subject: [PATCH] Add test to handle wrong topic format An associated test should be done on the gateway to not generate such topic --- wirepas_mqtt_library/wirepas_network_interface.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wirepas_mqtt_library/wirepas_network_interface.py b/wirepas_mqtt_library/wirepas_network_interface.py index 988fed0..666c8c9 100644 --- a/wirepas_mqtt_library/wirepas_network_interface.py +++ b/wirepas_mqtt_library/wirepas_network_interface.py @@ -272,8 +272,14 @@ def _on_data_received(self, client, userdata, message): data = wmm.ReceivedDataEvent.from_payload(message.payload) if data.network_address is None: # Network id is from topic - _, _, network_address, _, _ = TopicParser.parse_received_data_topic(message.topic) - data.network_address = network_address + try: + _, _, network_address, _, _ = TopicParser.parse_received_data_topic(message.topic) + data.network_address = network_address + except ValueError: + logging.error("Cannot determine network address from topic: %s",message.topic) + # Address is unknown but still dispatch data + data.network_address = None + self._task_queue.add_task(self._dispatch_uplink_data, data) except wmm.GatewayAPIParsingException as e: logging.error(str(e))