Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix BELGIUM_MAXIMUM_DEMAND_MONTH regex #128

Conversation

koen-dejonghe
Copy link

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.

@@ -82,7 +82,7 @@
BELGIUM_VERSION_INFORMATION = r'\d-\d:96\.1\.4.+?\r\n'
BELGIUM_EQUIPMENT_IDENTIFIER = r'\d-0:96\.1\.1.+?\r\n'
BELGIUM_CURRENT_AVERAGE_DEMAND = r'\d-\d:1\.4\.0.+?\r\n'
BELGIUM_MAXIMUM_DEMAND_MONTH = r'\d-\d:1\.6\.0.+?\r\n'
BELGIUM_MAXIMUM_DEMAND_MONTH = r'(?<!\()\d-\d:1\.6\.0.+?\r\n' # negative lookbehind on ( to avoid conflict with BELGIUM_MAXIMUM_DEMAND_13_MONTHS
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would using

^\d-\d:1\.6\.0.+?\r\n

not be enough?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koen-dejonghe ? Could you check please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, ^\d-\d:1\.6\.0.+?\r\n does not match anything.

@ndokter
Copy link
Owner

ndokter commented Apr 5, 2023

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
Copy link
Collaborator

Both issues fixed in #132

@ndokter ndokter closed this in #132 Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants