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

📌 Pull Request: Refactor & Enhance dbus-opendtu #227

Merged
merged 32 commits into from
Dec 15, 2024
Merged

Conversation

0x7878
Copy link
Collaborator

@0x7878 0x7878 commented Nov 18, 2024

📌 Pull Request: Refactor & Enhance dbus-opendtu

Hi Team! 👋

This pull request introduces a series of improvements and refactorings to the dbus-opendtu project. The main highlights include enhanced code readability, better testing coverage, and streamlined business logic. Here’s a detailed breakdown:

Main Changes:

  • 🧪 Added Unit Tests:

    • Implemented unit tests for core functionalities.
    • Mocked requests.get to simulate different responses for robust testing scenarios.
    • Configured different test scenarios for comprehensive test coverage.
  • 🔄 Business Logic Updates:

    • Refactored the main Python file for better readability.
    • Centralized update triggers to avoid service-based updates for a more modular design.

🔧 Refactoring Highlights:

  • 📂 Code Structure:

    • Renamed and refactored dbus-opendtu for improved readability and maintainability.
    • Cleaned up test_dbus-opendtu.py by removing unused parameters and constants.
    • Moved constants to appropriate modules for better code organization.
    • Improved import structure for clarity and consistency.
  • 🛠️ Code Simplification:

    • Consolidated redundant code and removed unused paths in the DbusService constructor.
    • Updated logging statements for better traceability.
    • Unified file naming convention to use underscores (_) instead of hyphens (-).
    • Shifted utility functions to helper modules and included unit tests to boost test coverage.
    • Refactored _get_serial, _get_name, and _get_status_url methods for better encapsulation and readability.

🚀 Enhancements:

  • 📝 Test Coverage:

    • Achieved 66% code coverage with a focus on critical paths.
    • Added template and inverter-specific tests to cover more edge cases.
    • Adjusted ahoy_0.5.93_live.json to reflect new test configurations.
    • Relocated tests to the appropriate folder structure for clearer organization.
  • 🔍 Code Quality:

    • Replaced hardcoded values with constants to enhance maintainability.
    • Configured test coverage tools and scripts to ensure ongoing code quality.

image

🙋‍♂️ Request for Support:

I could use your help to push the project towards 100% code coverage. It's a time-consuming task, so any support would be appreciated! If you can contribute by adding tests or enhancing existing ones, that would be fantastic. Let's aim for perfection together! 🚀


Thanks for reviewing! 😊 Feel free to comment or provide feedback.

- Add .coveragerc file to control coverage.py and exclude certain directories from coverage analysis.
- Add run_coverage.sh script to run unit tests with coverage and generate coverage report.
Move functions to helpers instead of constants, add unit tests, and improve function to handle cases where there are no inverters or templates to query. Also, remove the dependency on running tests within the main function.
- Removed unreachable code in the _read_config_dtu method.
- Clarified the logic for reading the DTU variant and other configuration values.
- Ensured that the DTU variant is either constants.DTUVARIANT_OPENDTU or constants.DTUVARIANT_AHOY, raising an error otherwise.
- Improved readability and maintainability of the code.
- Added a new test case to verify that the number of inverters is correctly set in the DbusService.
- Configured the test with a specific DTU variant and number of inverters.
- Used mocking to simulate the configuration and requests.
- Included assertions to validate the expected behavior.
@henne49 henne49 marked this pull request as ready for review December 10, 2024 22:34
Copy link
Owner

@henne49 henne49 left a comment

Choose a reason for hiding this comment

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

I'm happy to approve the code

@henne49 henne49 merged commit 76a10ea into main Dec 15, 2024
3 checks passed
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.

2 participants