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

Implement inverter.py own logger / Python 3.9 retro-compatibility / Restore .connected attribute #35

Merged
merged 8 commits into from
Apr 3, 2024

Conversation

hchiper
Copy link
Contributor

@hchiper hchiper commented Apr 2, 2024

No description provided.

This is a proposal to replace the `match/case/case...` by `if/elif/elif.../else` in the function `.decode()` to ensure compatibility with python 3.9 and earlier.
The use of `match/case` in this function is the only place in the whole package where a construction requires python >= 3.10. The proposed modification seems worth because python 3.9 is still widely used; it is e.g. the version available in Debian/oldstable repositories, which is still supported.
This is a proposal to reintroduce the '.connected` attribute.
Its suppression in recent versions of the module causes errors in programs using earlier versions.
In this proposal, an equivalent is reintroduced, now as a property, relying directly on the new `.isConnected()` method.
Retro-compatibility with python 3.9
Reintroduce `.connected` attrubute
This proposal implements an own logger for the `sun2000_modbus.inverter` module. 
Before, it was using the default "root" logger. If a program using the module needed to mute its log messages, the only option was to mute the "root" logger, which also muted messages from all other loggers.
A module-specific logger can be tuned without impact on other loggers and its messages will clearly display their origin as "sun2000_modbus.inverter" instead of "root".

Usage examples (in a custom program):
1°) catch the logger
    inv_log = logging.getLogger("sun2000_modbus.inverter")
2°) use one of the following instructions
    inv_log.setLevel(logging.INFO)  # original behaviour
    inv_log.setLevel(logging.ERROR)  # or any other level
    inv_log.disabled = True  # disables this logger only
Implement sun2000_modbus.inverter own logger
@olivergregorius olivergregorius added the enhancement New feature or request label Apr 2, 2024
@olivergregorius olivergregorius added this to the 2.2.0 milestone Apr 2, 2024
@olivergregorius olivergregorius linked an issue Apr 2, 2024 that may be closed by this pull request
@olivergregorius
Copy link
Owner

Hey @hchiper,

you just added the compatibility for Python 3.9 as you requested in #27. What about the locale formatting described there? Should this also be included in this PR?

Otherwise I would approve this PR, merge it and close the ticket.

Kind regards,
Oliver

hchiper and others added 2 commits April 3, 2024 11:58
This proposal implements the formatting numbers with the proper thousand separator and decimal sign according to the locale for the `.read_formatted()` function.

To use this feature, a module should at first
`
    import locale
    locale.setlocale(locale.LC_ALL, '')
`
and then call `.read_formatted()` with the named parameter `use_locale` set to `True`, for example: `read_formatted(register, use_locale=True)`.
@olivergregorius olivergregorius merged commit 99ef817 into olivergregorius:main Apr 3, 2024
1 check passed
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 this pull request may close these issues.

Python 3.9 retrocompatibility / Format using locale
2 participants