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

Improve OBIS string parsing #39

Closed
Krolken opened this issue May 20, 2021 · 0 comments · Fixed by #43
Closed

Improve OBIS string parsing #39

Krolken opened this issue May 20, 2021 · 0 comments · Fixed by #43
Assignees
Labels
enhancement New feature or request

Comments

@Krolken
Copy link
Contributor

Krolken commented May 20, 2021

As of now we can only parse an OBIS code from a dotted representation like 0.0.1.8.0.255

But the "normal" way of writing the obis would be 0-0:1.8.0.255 or even 0-0:1.8.0 as the last 255 usually can be omitted (but not in the byte representation)

What we would like is a from_string method that can handle any configuration.

0-0:1.8.0.255 can easily be parsed with regex.
0-0:1.8.0 should also be parsed with regex.

We might even be able to specify that we can have any delimiter. This could come in handy as we in some application have to use 0-0-1-8-0-255 as dot has special meaning in strings.

Some older meters using IEC62056-21 only uses a 3 char representation like 1.8.0 but this should no be allowed as we would not be able to transform back and forth with this.

We should also change the method to_string to have a standard format of the "normal" representation with a option to
add a custom delimiter:

def to_string(delimiter: Optional[str] = None)
    if delimiter is not None:
        return f"{a}-{b}:{c}.{e}.{f}.{g}"
    else:
        return  f"{a}{delimiter}{b}{delimiter}{c}{delimiter}{e}{delimiter}{f}{delimiter}{g}"
@Krolken Krolken added the enhancement New feature or request label May 20, 2021
@Krolken Krolken self-assigned this May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant