Skip to content

fix: No Contracts text in Multi Contract Config Flow #257

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

GuyKh
Copy link
Owner

@GuyKh GuyKh commented May 25, 2025

PR Type

Bug fix, Enhancement, Documentation


Description

  • Fixes handling and messaging for "no contracts found" in config flow.

    • Adds explicit error when no contracts are available.
    • Differentiates between "no contracts" and "no contracts selected".
  • Updates English and Hebrew translations for new error messages.

  • Improves logging formatting and consistency in coordinator.


Changes walkthrough 📝

Relevant files
Bug fix
config_flow.py
Enhance error handling for contract selection in config flow

custom_components/iec/config_flow.py

  • Adds explicit error when no contracts are found.
  • Differentiates between "no contracts" and "no contracts selected".
  • Updates error keys for clarity in contract selection.
  • +4/-2     
    Enhancement
    coordinator.py
    Refactor and clarify logging for readings and devices       

    custom_components/iec/coordinator.py

  • Refactors logging to use consistent string formatting.
  • Improves debug messages for missing readings and devices.
  • Adjusts formatting for multi-line log messages.
  • +20/-9   
    Documentation
    en.json
    Update English translations for contract errors                   

    custom_components/iec/translations/en.json

  • Adds "no_contracts" and "no_selected_contracts" error messages.
  • Updates contract selection description and error section.
  • Improves clarity of user-facing error messages.
  • +6/-2     
    he.json
    Update Hebrew translations for contract errors                     

    custom_components/iec/translations/he.json

  • Adds Hebrew translations for "no_contracts" and
    "no_selected_contracts".
  • Updates contract selection description and error section.
  • Ensures accurate and clear user messaging in Hebrew.
  • +6/-2     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Log Level

    The PR uses _LOGGER.warn() which is deprecated in favor of _LOGGER.warning(). This should be updated to use the recommended warning method.

    _LOGGER.warn(
        f"Failed to calculate Future Consumption, Assuming last meter read \
        ({last_meter_read}) as full consumption"
    )

    Copy link

    qodo-merge-pro bot commented May 25, 2025

    PR Code Suggestions ✨

    Latest suggestions up to af0038d

    CategorySuggestion                                                                                                                                    Impact
    Incremental [*]
    Handle potential None value

    The code doesn't check if readings.meter_start_date is None before using it,
    which could cause a TypeError if readings has a None value for meter_start_date.

    custom_components/iec/coordinator.py [710-717]

     month_ago_time = max(
         month_ago_time,
         TIMEZONE.localize(
             datetime.combine(
                 readings.meter_start_date, datetime.min.time()
             )
    -    ),
    +    ) if readings.meter_start_date is not None else month_ago_time,
     )
    • Apply / Chat
    Suggestion importance[1-10]: 8

    __

    Why: This suggestion addresses a potential bug where readings.meter_start_date could be None, which would cause a TypeError. Handling this improves robustness and prevents runtime errors, making it an important fix.

    Medium
    Fix exception logging

    The logger's warning method requires the exception as a separate argument using
    the exc_info parameter, not as a second positional argument. This will cause the
    exception details to be lost.

    custom_components/iec/coordinator.py [594]

    -_LOGGER.warning("Failed to calculate estimated next bill", e)
    +_LOGGER.warning("Failed to calculate estimated next bill", exc_info=e)
    • Apply / Chat
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies that the logger should use the exc_info keyword argument to properly log exception details. This improves error traceability but is not critical to functionality, so a moderate score is appropriate.

    Medium
    Fix string formatting

    The backslash continuation in the f-string will include the indentation in the
    output string, causing unwanted whitespace. Use parentheses for line
    continuation instead.

    custom_components/iec/coordinator.py [1028-1031]

     _LOGGER.warning(
    -    f"Failed to calculate Future Consumption, Assuming last meter read \
    -    ({last_meter_read}) as full consumption"
    +    f"Failed to calculate Future Consumption, Assuming last meter read "
    +    f"({last_meter_read}) as full consumption"
     )
    • Apply / Chat
    Suggestion importance[1-10]: 6

    __

    Why: The suggestion improves the log message formatting by removing unwanted whitespace, enhancing readability. While helpful, it is a minor improvement and does not affect core functionality.

    Low
    • More

    Previous suggestions

    Suggestions up to commit 760f270
    CategorySuggestion                                                                                                                                    Impact
    General
    Use correct logging method

    The warn method is deprecated in the Python logging module. Use warning instead
    for better compatibility and to avoid deprecation warnings. This ensures proper
    logging functionality.

    custom_components/iec/coordinator.py [1028-1031]

    -_LOGGER.warn(
    +_LOGGER.warning(
         f"Failed to calculate Future Consumption, Assuming last meter read \
         ({last_meter_read}) as full consumption"
     )
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion is accurate and important: using warning instead of the deprecated warn method ensures compatibility with the Python logging module and prevents deprecation warnings, which is a best practice for robust logging.

    Medium
    Possible issue
    Fix translation structure

    The "no_contracts" message is incorrectly placed in the "data" section of the
    translation file. This should be moved to the "error" section where it's
    actually used in the code. The "data" section is for form field labels, not
    error messages.

    custom_components/iec/translations/en.json [82-87]

     "select_contracts": {
         "title": "Select Contract",
    -    "description": "Select which contract to use",
    -    "data": {
    -        "no_contracts": "No Contracts Found"
    -    }
    +    "description": "Select which contract to use"
     },
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies that error messages like "no_contracts" should be placed in the "error" section, not under "data" in the translation file. This improves translation structure and maintainability, though it does not affect runtime logic.

    Medium

    @GuyKh GuyKh force-pushed the no-contracts-in-config-flow branch from 760f270 to af0038d Compare May 25, 2025 08:41
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant