make all objects able to print their own values

This commit is contained in:
Hans Erik van Elburg
2020-05-12 23:45:16 +02:00
parent 9610fbc3c1
commit a0ce89054a
5 changed files with 51 additions and 4 deletions

View File

@@ -183,7 +183,7 @@ class CosemParser(DSMRObjectParser):
return CosemObject(self._parse(line))
class ProfileGenericParser(DSMRObjectParser):
class ProfileGenericParser(object):
"""
Power failure log parser.
@@ -205,6 +205,22 @@ class ProfileGenericParser(DSMRObjectParser):
9) Unit of buffer values (Unit of capture objects attribute)
"""
def _parse(self, line):
# Match value groups, but exclude the parentheses. Adapted to also match OBIS code in 3rd position.
pattern = re.compile(r'((?<=\()[0-9a-zA-Z\.\*\-\:]{0,}(?=\)))')
values = re.findall(pattern, line)
# Convert empty value groups to None for clarity.
values = [None if value == '' else value for value in values]
buffer_length = int(values[0])
if (not values) or (len(values) != (buffer_length * 2 + 2)):
raise ParseError("Invalid '%s' line for '%s'", line, self)
return [self.value_formats[i].parse(value)
for i, value in enumerate(values)]
def parse(self, line):
raise NotImplementedError()