Open
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
added 2 commits
April 5, 2026 21:55
added 5 commits
April 19, 2026 22:24
- Add debug logging in sofar_client.py to log register and payload when handling write requests - Add debug logging in converter.py to log register and value in to_raw() method - Check for None register in both locations to catch the root cause
- Add debug logging in sofar_client.py to log register and payload when handling write requests - Add debug logging in converter.py to log register and value in to_raw() method - Check for None register in both locations to catch the root cause
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi Richard. Sorry for the entirely AI-generated PR description, but I think it should describe the changes accuratedly.
In a nutshell:
No behavior change expected.
I tested it on my ME3000SP:
Could you try testing on your own inverter? Thanks!
PR Summary: Major Refactor - Modular Architecture with Comprehensive Testing
Overall Impact
This PR represents a complete architectural refactor of the sofar2mqtt codebase, transforming it from a monolithic single-file script (
sofar2mqtt-v2.py) into a well-structured, production-ready Python package with proper modularity, type safety, and test coverage.Structural Changes
sofar2mqtt-v2.py)config/loader.pywith Pydantic validationcore/modbus_client.pywith thread-safe wrappermqtt/client.pyandmqtt/discovery.pytransformations/converter.pycli.pyand proper package entry pointsKey Improvements
Modular Architecture (6 core modules)
sofar2mqtt/models/- Pydantic data models (RegisterDefinition,InverterConfig)sofar2mqtt/core/- Business logic (ModbusClient,SofarClient)sofar2mqtt/mqtt/- MQTT client and HA discoverysofar2mqtt/config/- Configuration loading and validationsofar2mqtt/transformations/- Value conversion utilitiessofar2mqtt/utils/- Cross-cutting concerns (retry, logging)Type Safety - Pydantic v2 models for all data structures with validation
Dependency Injection - Components passed to
SofarClientrather than created internally, enabling easy testingCLI with Click - Full argument parsing with environment variable support and help text
Modern Tooling
pyproject.tomlwith proper package metadata and dev dependenciesruff.tomlfor linting/formatting configurationtests.yml) with coverage reportingTest Coverage (75 Tests, 64% Code Coverage)
New Tests Added:
tests/test_modbus.pytests/test_mqtt.pytests/test_sofar_client.pytests/test_transformations.pyTest Scenarios Covered:
Testing on ME3000SP
The refactor maintains full compatibility with existing configurations (config files unchanged) while adding the ability to automatically detect device type and load appropriate configuration.
Breaking Changes / Notes
sofar2mqtt-v2.pyremoved (replaced bysofar2mqtt/package)python sofar2mqtt-v2.py ...tosofar2mqtt ...