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

Python 3.9 retrocompatibility / Format using locale #27

Closed
hchiper opened this issue Sep 2, 2023 · 1 comment · Fixed by #35
Closed

Python 3.9 retrocompatibility / Format using locale #27

hchiper opened this issue Sep 2, 2023 · 1 comment · Fixed by #35

Comments

@hchiper
Copy link
Contributor

hchiper commented Sep 2, 2023

First, thank a lot for sun2000_modbus.
I am using it with Python 3.9, so in sun2000_modbus/datatypes.py I had to replace the match/case/case... by if/elif/elif.../else in decode().
I also found very convenient to modify sun2000_modbus/inverter.py in order to benefit from the locale formatting in read_formatted(). To achieve this goal, I modified it in the following way:

def read_formatted(self, register, use_locale=False):  # added the argument use_locale
    # (...)
    if register.value.unit is not None:
        if use_locale:
            return f'{value:n} {register.value.unit}'  # added the :n to format according to the locale's thousand separator, decimal sign
        else:
            return f'{value} {register.value.unit}'
    # (...)

Maybe you could consider worth to include these modifications in your sources.

@olivergregorius
Copy link
Owner

Hi @hchiper, thanks for your contribution.
What do you think about creating a Pull Request containing your changes?
After a review I could simply merge it and create a new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants