From 6cca9898e52071e5d399823b80c3e0ca0f3a0205 Mon Sep 17 00:00:00 2001 From: alindman Date: Wed, 28 Jun 2023 20:20:53 +0200 Subject: [PATCH] Convert result to str before regex Also more logging if there are no matches. --- dripline/implementations/entity_endpoints.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dripline/implementations/entity_endpoints.py b/dripline/implementations/entity_endpoints.py index cd6f24bd..d26007a5 100644 --- a/dripline/implementations/entity_endpoints.py +++ b/dripline/implementations/entity_endpoints.py @@ -133,10 +133,14 @@ def on_get(self): result = self.service.send_to_device([self._get_str]) logger.debug(f'result is: {result}') if self._extract_raw_regex is not None: - first_result = result + try: + first_result = str(result) + except: + logger.error('Failed to convert {} to string'.format(result)) + raise ThrowReply('resource_error', 'Failed to convert [{}] to string'.format(result)) matches = re.search(self._extract_raw_regex, first_result) if matches is None: - logger.error('matching returned none') + logger.error('matching [{}] with regex [{}] returned none'.format(first_result, self._extract_raw_regex)) # exceptions.DriplineValueError raise ThrowReply('resource_error', 'device returned unparsable result, [{}] has no match to input regex [{}]'.format(first_result, self._extract_raw_regex)) logger.debug(f"matches are: {matches.groupdict()}")