catch parse errors in TelegramParser, ignore lines that can not be parsed

This commit is contained in:
Hans Erik van Elburg 2021-02-07 13:40:20 +01:00
parent 3dc77a8231
commit 1cdda2eaba

View File

@ -10,7 +10,6 @@ logger = logging.getLogger(__name__)
class TelegramParser(object): class TelegramParser(object):
crc16_tab = [] crc16_tab = []
def __init__(self, telegram_specification, apply_checksum_validation=True): def __init__(self, telegram_specification, apply_checksum_validation=True):
@ -56,7 +55,11 @@ class TelegramParser(object):
# Some signatures are optional and may not be present, # Some signatures are optional and may not be present,
# so only parse lines that match # so only parse lines that match
if match: if match:
try:
telegram[signature] = parser.parse(match.group(0)) telegram[signature] = parser.parse(match.group(0))
except Exception:
logger.error("ignore line with signature {}, because parsing failed.".format(signature),
exc_info=True)
return telegram return telegram
@ -219,6 +222,7 @@ class ProfileGenericParser(DSMRObjectParser):
8) Buffer value 2 (oldest entry of buffer attribute without unit) 8) Buffer value 2 (oldest entry of buffer attribute without unit)
9) Unit of buffer values (Unit of capture objects attribute) 9) Unit of buffer values (Unit of capture objects attribute)
""" """
def __init__(self, buffer_types, head_parsers, parsers_for_unidentified): def __init__(self, buffer_types, head_parsers, parsers_for_unidentified):
self.value_formats = head_parsers self.value_formats = head_parsers
self.buffer_types = buffer_types self.buffer_types = buffer_types
@ -271,7 +275,6 @@ class ValueParser(object):
self.coerce_type = coerce_type self.coerce_type = coerce_type
def parse(self, value): def parse(self, value):
unit_of_measurement = None unit_of_measurement = None
if value and '*' in value: if value and '*' in value: