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: handle missing QR code #64

Closed
wants to merge 3 commits into from
Closed

feat: handle missing QR code #64

wants to merge 3 commits into from

Conversation

mikejgray
Copy link
Collaborator

@mikejgray mikejgray commented Jan 25, 2025

chore: allow newer versions of websockets
fix: increase websocket max size to 5MB from 1MB

Closes a number of issues ahead of the merge of this plugin with its associated skill.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added integration with Home Assistant platform
    • Enhanced WebSocket connection capabilities
  • Bug Fixes

    • Improved error handling for QR code OAuth process
    • Added handling for cases where QR code URL retrieval fails
  • Dependencies

    • Updated websockets and added websocket-client package
    • Increased WebSocket message size limit to 5 MB

If the QR code is not successfully generated, send the user a notification. A notification is chosen for persistence, otherwise text on the screen may be lost on boot.

Closes #49
Copy link

coderabbitai bot commented Jan 25, 2025

Warning

Rate limit exceeded

@mikejgray has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 26 minutes and 33 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 d17f1ae and 81a08a2.

📒 Files selected for processing (1)
  • ovos_PHAL_plugin_homeassistant/logic/socketclient.py (1 hunks)

Walkthrough

This pull request introduces enhancements to the Home Assistant integration plugin, focusing on WebSocket connection improvements and OAuth error handling. The changes include updating the WebSocket connection to support larger message sizes, adding error handling for QR code retrieval during OAuth, and modifying dependency requirements. A test script is also included to demonstrate the plugin's instantiation with a specific configuration.

Changes

File Change Summary
DO_NOT_COMMIT.py Added test script instantiating HomeAssistantPlugin with FakeBus and specific configuration
ovos_PHAL_plugin_homeassistant/__init__.py Added error handling for QR code URL retrieval during OAuth process
ovos_PHAL_plugin_homeassistant/logic/socketclient.py Updated WebSocket connection to support 5 MB maximum message size
requirements.txt Updated websockets version constraint and added websocket-client dependency

Sequence Diagram

sequenceDiagram
    participant Plugin as HomeAssistantPlugin
    participant WebSocket as WebSocket Connection
    participant OAuth as OAuth Service

    Plugin->>OAuth: Initiate OAuth Process
    OAuth-->>Plugin: Request QR Code
    alt QR Code Retrieved
        Plugin->>Plugin: Process QR Code URL
    else QR Code Not Retrieved
        Plugin->>Plugin: Display Error Notification
    end
    Plugin->>WebSocket: Establish Connection (5 MB Max)
    WebSocket-->>Plugin: Connection Established
Loading

Possibly related PRs

Suggested reviewers

  • JarbasAl
  • NeonDaniel

Poem

🤖 Behold, a WebSocket's mighty leap,
With messages now five megs deep!
OAuth's QR code, no longer shy,
Errors caught with a rabbit's eye 🐰
Home Assistant, now more bright and clear,
Integration's magic drawing near! 🏠✨


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

@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)
ovos_PHAL_plugin_homeassistant/logic/socketclient.py (1)

49-49: Consider making the WebSocket max_size configurable.

The WebSocket message size limit is hardcoded to 5MB. Consider making this value configurable through the plugin's configuration to allow users to adjust it based on their needs.

-            self.websocket = await websockets.connect(uri=uri, close_timeout=5, open_timeout=5, max_size=5242880)
+            max_size = self.config.get("websocket_max_size", 5242880)  # Default to 5MB
+            self.websocket = await websockets.connect(uri=uri, close_timeout=5, open_timeout=5, max_size=max_size)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c63a179 and d17f1ae.

📒 Files selected for processing (4)
  • DO_NOT_COMMIT.py (1 hunks)
  • ovos_PHAL_plugin_homeassistant/__init__.py (1 hunks)
  • ovos_PHAL_plugin_homeassistant/logic/socketclient.py (1 hunks)
  • requirements.txt (1 hunks)
🧰 Additional context used
🪛 Gitleaks (8.21.2)
DO_NOT_COMMIT.py

6-6: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)

🔇 Additional comments (3)
DO_NOT_COMMIT.py (1)

1-11: ⚠️ Potential issue

Remove this file or move it to a test directory.

This appears to be a test file that should not be committed to the repository. If this is test code, consider:

  1. Moving it to a proper test directory.
  2. Using environment variables or configuration files for sensitive data.
  3. Adding it to .gitignore.

Additionally:

  1. The JWT token is exposed, which is a security risk.
  2. The WebSocket URL is hardcoded with an IP address, making it environment-specific.

Let's verify if this file is already in .gitignore:

🧰 Tools
🪛 Gitleaks (8.21.2)

6-6: Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.

(jwt)

ovos_PHAL_plugin_homeassistant/__init__.py (1)

886-888: LGTM! Good error handling improvement.

The added check for missing QR code and user notification improves the error handling, providing better feedback to users when QR code generation fails.

requirements.txt (1)

8-8: LGTM! Good version constraints with clear comments.

The version constraints are well-documented with comments explaining the reasons for the version limits.

Let's verify the latest versions and any known vulnerabilities:

Also applies to: 11-11

✅ Verification successful

Version constraints are secure and well-justified

The specified version range (>=0.54.0,<14.0) is secure and avoids all known vulnerabilities. The upper bound restriction is well-documented, preventing exposure to breaking changes in 14.0+.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check latest versions and vulnerabilities for websockets packages

# Check PyPI for latest versions
echo "Latest versions from PyPI:"
curl -s https://pypi.org/pypi/websockets/json | jq -r '.info.version'
curl -s https://pypi.org/pypi/websocket-client/json | jq -r '.info.version'

# Check for security advisories
echo -e "\nSecurity advisories from GitHub:"
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "websockets") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'
'

Length of output: 1213

@mikejgray mikejgray closed this Jan 25, 2025
@mikejgray mikejgray deleted the FEAT_Multiple branch January 25, 2025 18:03
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.

1 participant