Skip to content

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Aug 16, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Device identifier validation now safely handles non-string or malformed inputs, returning invalid instead of raising errors to improve stability.
  • Chores

    • Changelog updated with an ongoing entry for PR 321 and tidy-up of prior entries.

@coderabbitai
Copy link

coderabbitai bot commented Aug 16, 2025

Walkthrough

Added an Ongoing CHANGELOG bullet for PR 321. In plugwise_usb/helpers/util.py, validate_mac now catches TypeError for non-string inputs and returns False; no other functional or public API changes.

Changes

Cohort / File(s) Change Summary
Documentation
CHANGELOG.md
Added new Ongoing bullet for PR 321 ("Catch error reported in Issue #312"); existing PR 319 bullet remains. No other edits.
Utilities
plugwise_usb/helpers/util.py
validate_mac(mac: str) -> bool updated to wrap the regex check in a try/except catching TypeError and returning False for non-string inputs; remaining logic unchanged. No public signatures changed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibble on commits with whiskers bright,
A tiny try/except tucks TypeError tight.
CHANGELOG crumbs for three-two-one,
MACs behave now — quiet as a bun. 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch impr-312

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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 or @coderabbitai title 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 1

🧹 Nitpick comments (2)
CHANGELOG.md (1)

5-5: Replace placeholders with actual PR and Issue links

The CHANGELOG entry has empty links. Please fill in the PR number and the correct Issue URL to keep the log useful.

Proposed change:

-- PR [](): Catch error from Issue [#312]()
+- PR [321](https://github.com/plugwise/python-plugwise-usb/pull/321): Catch error from Issue [#312](<INSERT_CORRECT_ISSUE_URL>)

Can you confirm the correct repository for Issue #312 (plugwise/plugwise-beta vs plugwise/plugwise_usb-beta) so we can insert the proper URL?

plugwise_usb/helpers/util.py (1)

17-21: Good guard for None/non-strings; consider simplifying and keeping semantics explicit

Catching TypeError here solves the reported issue when mac is None. To improve readability and avoid using exceptions for control flow, an explicit type check is cleaner while preserving the existing behavior (uppercase hex only).

Suggested refactor:

-    try:
-        if not re.match("^[A-F0-9]+$", mac):
-            return False
-    except TypeError:
-        return False
+    if not isinstance(mac, str):
+        return False
+    if not re.match("^[A-F0-9]+$", mac):
+        return False

Optional follow-up (if acceptable): use re.fullmatch for clarity instead of anchoring with ^$:

-    if not re.match("^[A-F0-9]+$", mac):
+    if re.fullmatch(r"[A-F0-9]+", mac) is None:
         return False

If helpful, I can add a small unit test asserting validate_mac(None) is False to prevent regressions.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 77b0375 and 21f9d5b.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • plugwise_usb/helpers/util.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
plugwise_usb/helpers/util.py (1)
plugwise_usb/exceptions.py (1)
  • NodeError (24-25)
🪛 GitHub Actions: Latest commit
plugwise_usb/helpers/util.py

[error] 10-10: Ruff: F401 unused import 'NodeError' in plugwise_usb/helpers/util.py:10. Remove unused import. 1 fixable with --fix.

@codecov
Copy link

codecov bot commented Aug 16, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.56%. Comparing base (77b0375) to head (64ee4f6).

Files with missing lines Patch % Lines
plugwise_usb/helpers/util.py 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #321      +/-   ##
==========================================
+ Coverage   80.50%   80.56%   +0.06%     
==========================================
  Files          36       36              
  Lines        7555     7558       +3     
==========================================
+ Hits         6082     6089       +7     
+ Misses       1473     1469       -4     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bouwew bouwew marked this pull request as ready for review August 16, 2025 10:21
@bouwew bouwew requested a review from a team as a code owner August 16, 2025 10:21
Copy link
Contributor

@dirixmjm dirixmjm left a comment

Choose a reason for hiding this comment

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

LGM!

@sonarqubecloud
Copy link

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 (3)
plugwise_usb/helpers/util.py (3)

14-15: Align the type hint/docstring with the new behavior (accepting None).

Since validate_mac now explicitly handles non-string inputs (e.g., None) by returning False, reflect that in the type hint and docstring for clarity and to help static analysis.

Apply this diff:

-def validate_mac(mac: str) -> bool:
-    """Validate the supplied string is in a MAC address format."""
+def validate_mac(mac: str | None) -> bool:
+    """Validate MAC-like hex string without separators; returns False for None/non-str."""

17-17: Prefer re.fullmatch over re.match with anchors for clarity.

Functionally equivalent here, but fullmatch makes the intent explicit and avoids ^/$ anchors.

Apply this diff:

-        if not re.match("^[A-F0-9]+$", mac):
+        if not re.fullmatch(r"[A-F0-9]+", mac):

22-25: Defensive: also catch TypeError on int(.., 16) conversion.

Not strictly necessary given the earlier regex guard, but broadening the exception here makes this block robust if the first guard is ever refactored.

Apply this diff:

-    except ValueError:
+    except (ValueError, TypeError):
         return False
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 64ee4f6 and e042352.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • plugwise_usb/helpers/util.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run pytest using Python 3.13
🔇 Additional comments (1)
plugwise_usb/helpers/util.py (1)

16-20: Graceful handling of non-string MACs (fix for #312) — LGTM

Catching TypeError around the regex check cleanly prevents crashes on None/bytes inputs and correctly returns False. This is a minimal, safe change with no API breakage.

@bouwew bouwew merged commit 6be2724 into main Aug 16, 2025
15 checks passed
@bouwew bouwew deleted the impr-312 branch August 16, 2025 12:04
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.

3 participants