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

feat: add latest_meter_reading_date sensor #105

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

GuyKh
Copy link
Owner

@GuyKh GuyKh commented Apr 28, 2024

Type

enhancement


Description

  • Added a new sensor elec_latest_meter_reading_date in sensor.py to track the date of the latest meter reading.
  • Included English and Hebrew translations for the new sensor in en.json and he.json.

Changes walkthrough

Relevant files
Enhancement
sensor.py
Add latest meter reading date sensor                                         

custom_components/iec/sensor.py

  • Added a new sensor for elec_latest_meter_reading_date to track the
    latest meter reading date.
  • +6/-0     
    en.json
    Add English translation for latest meter reading date       

    custom_components/iec/translations/en.json

  • Added English translation for the new elec_latest_meter_reading_date
    sensor.
  • +3/-0     
    he.json
    Add Hebrew translation for latest meter reading date         

    custom_components/iec/translations/he.json

  • Added Hebrew translation for the new elec_latest_meter_reading_date
    sensor.
  • +3/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @GuyKh GuyKh self-assigned this Apr 28, 2024
    @GuyKh GuyKh added the enhancement New feature or request label Apr 28, 2024
    Copy link

    what-the-diff bot commented Apr 28, 2024

    PR Summary

    • New Feature Addition to the Sensor System
      A fresh entity named elec_latest_meter_reading_date has been introduced. This will allow users to access the latest meter reading date directly through the sensor.

    • Language Support Increased
      To ensure inclusivity and ease of use for non-English speakers, translations for elec_latest_meter_reading_date have been made available in both English and Hebrew. This will facilitate a wider audience to effectively use this new feature.

    Copy link

    PR Description updated to latest commit (bdb1099)

    Copy link

    PR Review

    ⏱️ Estimated effort to review [1-5]

    2, because the changes are straightforward and localized to specific files, involving the addition of a new sensor and its translations. The logic is simple and the modifications are minimal.

    🧪 Relevant tests

    No

    🔍 Possible issues

    Possible Bug: In the Hebrew translation file (he.json), the key for the new sensor translation is duplicated as "elec_latest_meter_reading". This should be "elec_latest_meter_reading_date" to match the English version and the sensor's key.

    🔒 Security concerns

    No


    ✨ Review tool usage guide:

    Overview:
    The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

    The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

    • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
    /review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
    
    [pr_reviewer]
    some_config1=...
    some_config2=...
    

    See the review usage page for a comprehensive guide on using this tool.

    Copy link

    PR Code Suggestions

    CategorySuggestions                                                                                                                                                       
    Bug
    Replace the default integer return value with None for the date sensor when data is unavailable.

    The value_fn lambda for the elec_latest_meter_reading_date sensor incorrectly returns an
    integer 0 when the desired attribute is not available. This is not suitable for a sensor
    with a device_class of DATE. Instead, it should return None to indicate the absence of a
    date.

    custom_components/iec/sensor.py [139]

     value_fn=lambda data: (data[FUTURE_CONSUMPTIONS_DICT_NAME][data[ATTRIBUTES_DICT_NAME][METER_ID_ATTR_NAME]]
    -                       .total_import_date or 0) if (data[FUTURE_CONSUMPTIONS_DICT_NAME]) else None
    +                       .total_import_date) if (data[FUTURE_CONSUMPTIONS_DICT_NAME]) else None
     
    Correct the translation key to match its unique identifier.

    The key for the Hebrew translation of "IEC latest meter reading date" is duplicated as
    "elec_latest_meter_reading", which is already used for another sensor. This should be
    corrected to a unique key, such as "elec_latest_meter_reading_date" to match the English
    translation file and avoid conflicts.

    custom_components/iec/translations/he.json [27-28]

    -"elec_latest_meter_reading": {
    +"elec_latest_meter_reading_date": {
       "name": "תאריך קריאת מונה אחרונה {multi_contract}"
     }
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

    • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    
    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    

    See the improve usage page for a comprehensive guide on using this tool.

    @GuyKh GuyKh force-pushed the main branch 2 times, most recently from 8130b63 to dce28a3 Compare September 24, 2024 08:00
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant