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

Add telegram() method to both API versions (#430) #491

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

Conversation

Mausy5043
Copy link

@Mausy5043 Mausy5043 commented Feb 1, 2025

This should fix #430.
A new method telegram() is added to both API versions v1 and v2.
This returns the output of the api/v1/telegram and api/telegram endpoints respectively.
All processing is left to the client. Even the return type is not presumed.

Summary by CodeRabbit

  • New Features

    • Added telegram() method to retrieve the latest telegram data across different API versions (V1 and V2).
    • Introduced supports_telegram() method to check device support for telegram functionality.
    • Updated README import statement to use the correct class name.
  • Documentation

    • Simplified import example in README.
    • Added example usage for retrieving raw telegram data from the API.
    • Updated error message in the identify method for clarity.

Return type is `Any` because we don't process the response from the API.
Copy link
Contributor

coderabbitai bot commented Feb 1, 2025

Warning

Rate limit exceeded

@Mausy5043 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c59482c and 1c56085.

📒 Files selected for processing (1)
  • homewizard_energy/models.py (1 hunks)

Walkthrough

This pull request introduces a new telegram() method across different versions of the HomeWizard Energy API classes (V1 and V2). The method is designed to retrieve the most recent telegram data from a P1 meter device. The implementation varies slightly between versions but follows a consistent pattern of making an API request to fetch unprocessed telegram data. The README.md file was also updated to reflect a minor import statement change.

Changes

File Change Summary
README.md Updated import statement from HomeWizardEnergyV1V1 to HomeWizardEnergyV1 and added example code for telegram() method.
homewizard_energy/homewizard_energy.py Added abstract telegram() method with NotImplementedError.
homewizard_energy/v1/__init__.py Added telegram() method to retrieve raw telegram data from /api/v1/telegram endpoint and updated error message in identify method.
homewizard_energy/v2/__init__.py Added telegram() method with @authorized_method decorator to retrieve telegram data from /api/telegram endpoint.
homewizard_energy/models.py Added supports_telegram() method to check if the device supports telegram functionality.

Assessment against linked issues

Objective Addressed Explanation
Add await api.telegram() functionality
Inspect most recent telegram from P1-meter

Possibly related PRs


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
homewizard_energy/homewizard_energy.py (1)

85-88: Add docstring details to match implementation classes.

The docstring should clarify that this method returns unprocessed telegram data and reference the measurement method for parsed data, matching the V1/V2 implementations.

     async def telegram(self) -> Any:
-        """Get the latest telegram."""
+        """Return the most recent, valid telegram that was given by the device.
+        The telegram is not processed in any other form.
+        If you need parsed data, use the measurement method.
+        """
         raise NotImplementedError
README.md (1)

26-26: Consider adding telegram method example.

The import statement correction looks good. Consider adding an example of using the new telegram() method to demonstrate its usage for retrieving raw P1 meter data.

 from homewizard_energy import HomeWizardEnergyV1
+
+# Example of getting raw telegram data
+telegram = await api.telegram()
+print(telegram)  # Raw P1 meter data
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5681f9 and d830fe7.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • homewizard_energy/homewizard_energy.py (1 hunks)
  • homewizard_energy/v1/__init__.py (1 hunks)
  • homewizard_energy/v2/__init__.py (1 hunks)
🔇 Additional comments (2)
homewizard_energy/v1/__init__.py (1)

59-67: LGTM! Clean implementation of telegram method.

The implementation correctly follows the class patterns and includes clear documentation about the unprocessed nature of the returned data.

homewizard_energy/v2/__init__.py (1)

98-107: LGTM! Secure implementation with proper authorization.

The implementation correctly enforces authorization and follows the class patterns. The docstring clearly explains the unprocessed nature of the returned data.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
homewizard_energy/v1/__init__.py (1)

61-64: Consider enhancing the docstring with examples and return type info.

While the docstring clearly explains the purpose, it could be more helpful by including:

  • Example usage
  • Expected response structure
  • Return type description
     """Return the most recent, valid telegram that was given by the device.
     The telegram is not processed in any other form.
     If you need parsed data, use the measurement method.
+
+    Returns:
+        The raw telegram response from the device. Example:
+        {
+            "telegram": "/XMX5LGBBFG1009470632\r\n\r\n1-3:0.2.8(42)\r\n0-0:1.0.0(200308161442W)\r\n..."
+        }
     """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d30d8a4 and ce0c4cb.

📒 Files selected for processing (1)
  • homewizard_energy/v1/__init__.py (1 hunks)
🔇 Additional comments (1)
homewizard_energy/v1/__init__.py (1)

59-68: LGTM! Clean and focused implementation.

The implementation correctly follows the class patterns, uses appropriate error handling via the @optional_method decorator, and aligns with the PR objectives by returning unprocessed telegram data.

Copy link

codecov bot commented Feb 2, 2025

Codecov Report

Attention: Patch coverage is 41.17647% with 10 lines in your changes missing coverage. Please review.

Project coverage is 97.49%. Comparing base (b5681f9) to head (1c56085).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
homewizard_energy/v1/__init__.py 37.50% 5 Missing ⚠️
homewizard_energy/v2/__init__.py 40.00% 3 Missing ⚠️
homewizard_energy/homewizard_energy.py 50.00% 1 Missing ⚠️
homewizard_energy/models.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #491      +/-   ##
==========================================
- Coverage   99.14%   97.49%   -1.65%     
==========================================
  Files           9        9              
  Lines         582      598      +16     
  Branches       44       45       +1     
==========================================
+ Hits          577      583       +6     
- Misses          3       13      +10     
  Partials        2        2              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Reading telegrams from P1
1 participant