ndokter / dsmr_parser

Library to parse Dutch Smart Meter Requirements (DSMR) telegrams.
MIT License
110 stars 64 forks source link

fix BELGIUM_MAXIMUM_DEMAND_MONTH regex #128

Closed koen-dejonghe closed 1 year ago

koen-dejonghe commented 1 year ago

Regex for BELGIUM_MAXIMUM_DEMAND_MONTH will also match strings intended for BELGIUM_MAXIMUM_DEMAND_13_MONTHS. This results in an error, for example:

ignore line with signature \d-\d:1\.6\.0.+?\r\n, because parsing failed.
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/dsmr-mqtt/lib/python3.10/site-packages/dsmr_parser/parsers.py", line 90, in parse
    dsmr_object = parser.parse(match)
  File "/opt/homebrew/anaconda3/envs/dsmr-mqtt/lib/python3.10/site-packages/dsmr_parser/parsers.py", line 226, in parse
    values=self._parse(line)
  File "/opt/homebrew/anaconda3/envs/dsmr-mqtt/lib/python3.10/site-packages/dsmr_parser/parsers.py", line 198, in _parse
    raise ParseError("Invalid '%s' line for '%s'", line, self)
dsmr_parser.exceptions.ParseError: ("Invalid '%s' line for '%s'", '1-0:1.6.0)(1-0:1.6.0)(230101000000W)(221209193000W)(10.000*kW)(230201000000W)(230130184500W)(05.000*kW)\r\n', <dsmr_parser.parsers.MBusParser object at 0x1021aa170>)

We can avoid this by adding a negative lookbehind on '(' to the regex of BELGIUM_MAXIMUM_DEMAND_MONTH.

ndokter commented 1 year ago

Is it somehow reproducable in this unit test? TelegramParserFluviusTest

It's not clear to me why that telegram, which has both values, does not run into the issue

dupondje commented 1 year ago

Both issues fixed in #132