Skip to content

Conversation

@CoMPaTech
Copy link
Owner

@CoMPaTech CoMPaTech commented Aug 14, 2025

Summary by CodeRabbit

  • Chores

    • Added a local pre-commit hook to automate fixture generation when relevant files change.
  • Refactor

    • Standardized how intermediate derived data is produced and consumed across tooling and scripts.
  • Bug Fixes

    • Improved error reporting to include full stack traces.
    • Added clearer logging around data derivation and processing for easier troubleshooting.

@coderabbitai
Copy link

coderabbitai bot commented Aug 14, 2025

Walkthrough

Adds a local pre-commit hook to run a fixture-generation script; converts AirOS.derived_data to a staticmethod and updates its call sites; mashumaro-step-debug imports AirOS, derives data before deserialization, and uses _LOGGER.exception for errors; generate_ha_fixture updated to call the new signature.

Changes

Cohort / File(s) Summary
Pre-commit hook config
.pre-commit-config.yaml
Adds a local hook parsetest running script/run-in-env.sh python script/generate_ha_fixture.py, script-type with language: script, types: [python], pass_filenames: false, files regex for Python and userdata JSON; placed before existing pytest hook.
AirOS core change
airos/airos8.py
Converts AirOS.derived_data(...) from an instance method to a @staticmethod with signature derived_data(response: dict[str, Any]) -> dict[str, Any].
Fixture generation script
script/generate_ha_fixture.py
Updates call site to AirOS.derived_data(source_data) (removed None first arg and the type-ignore); passes result to AirOSData.from_dict and writes fixture unchanged otherwise.
Debug/deserialization script
script/mashumaro-step-debug.py
Imports AirOS from airos.airos8; calls derived_data = AirOS.derived_data(data) before AirOS8Data.from_dict; adds log "Deriving AirOS8Data from object..."; replaces formatted except Exception as e handling with _LOGGER.exception("The program failed") to log stack trace.

Sequence Diagram(s)

sequenceDiagram
  participant Raw as Raw input (response/source_data)
  participant AirOS as AirOS.derived_data (static)
  participant Parser as AirOS8Data / AirOSData.from_dict
  participant Writer as Fixture writer
  participant Logger as _LOGGER

  Raw->>AirOS: derived_data(response)
  AirOS-->>Parser: derived_data
  Parser->>Writer: from_dict(derived_data) -> write fixture / continue
  alt Error
    Parser-->>Logger: raise/exception
    Logger-->>Logger: _LOGGER.exception("The program failed") (stack trace)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

  • Fixture generation for derived #36 — touches script/generate_ha_fixture.py and shares changes to AirOS.derived_data call/sites.
  • Upd #62 — updates AirOS.derived_data API and related callers; likely overlaps refactor.
  • Add (very basic) test #10 — modifies the AirOS/AirOS8 class and constructor/connection behavior; related to class-level changes.

Poem

I hop to tweak the pre-commit,
A static hop, a cleaner fit.
I derive the data, then I parse,
I log the tumble, stack-trace sparse.
Fixtures bloom where carrots sit—🥕🐇

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

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

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.

@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.08%. Comparing base (40ea0e2) to head (3880dad).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #64   +/-   ##
=======================================
  Coverage   96.07%   96.08%           
=======================================
  Files           9        9           
  Lines        1352     1353    +1     
=======================================
+ Hits         1299     1300    +1     
  Misses         53       53           

☔ 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.

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: 3

🧹 Nitpick comments (1)
script/mashumaro-step-debug.py (1)

82-86: Elevate log level on failure and exit non‑zero for automation.

Since this is a debugging/validation script, failing with a non‑zero exit code helps CI and local workflows surface issues immediately. Also, use error level for the failure banner.

-    except Exception:
-        _LOGGER.info("\n------------------")
-        _LOGGER.info("CRITICAL ERROR FOUND!")
-        _LOGGER.exception("The program failed")
-        _LOGGER.info("------------------\n")
+    except Exception:
+        _LOGGER.error("\n------------------")
+        _LOGGER.error("CRITICAL ERROR FOUND!")
+        _LOGGER.exception("The program failed")
+        _LOGGER.error("------------------\n")
+        sys.exit(1)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 40ea0e2 and d0a247a.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml (1 hunks)
  • script/mashumaro-step-debug.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
script/mashumaro-step-debug.py (4)
airos/airos8.py (2)
  • AirOS (26-385)
  • derived_data (196-247)
airos/data.py (3)
  • AirOS8Data (559-576)
  • AirOSDataClass (107-110)
  • Derived (543-555)
tests/test_airos8.py (2)
  • test_derived_data_no_interfaces_key (106-110)
  • test_derived_data_no_br0_eth0_ath0 (114-124)
script/generate_ha_fixture.py (1)
  • generate_airos_fixtures (22-59)
🔇 Additional comments (1)
script/mashumaro-step-debug.py (1)

79-79: LGTM: Deserialize with derived data.

Feeding AirOS8Data.from_dict with the response augmented by derived aligns with the dataclass contract in airos.data and will catch missing interface scenarios early.

@sonarqubecloud
Copy link

@CoMPaTech CoMPaTech merged commit 3df1d63 into main Aug 14, 2025
13 of 14 checks passed
@CoMPaTech CoMPaTech deleted the upd branch August 14, 2025 08:02
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

🔭 Outside diff range comments (2)
airos/airos8.py (1)

186-188: Bug: logging uses coroutine object instead of response body

response.text is an async coroutine method; you already awaited response_text above. Logging response.text here will print a coroutine repr instead of the actual body.

Apply this diff:

-                    log = f"Login failed with status {response.status}. Full Response: {response.text}"
+                    log = f"Login failed with status {response.status}. Full Response: {response_text}"
script/generate_ha_fixture.py (1)

25-33: Gracefully handle missing userdata directory and ensure deterministic processing

  • If fixtures/userdata doesn’t exist (e.g., in a fresh checkout), pre-commit will fail. Handle this early and noop.
  • Sort filenames to make output deterministic across platforms.
  • Skip non-file entries defensively.

Apply this diff:

@@
-    fixture_dir = os.path.join(os.path.dirname(__file__), "../fixtures")
-    userdata_dir = os.path.join(os.path.dirname(__file__), "../fixtures/userdata")
+    fixture_dir = os.path.join(os.path.dirname(__file__), "../fixtures")
+    userdata_dir = os.path.join(os.path.dirname(__file__), "../fixtures/userdata")
@@
-    # Iterate over all files in the userdata_dir
-    for filename in os.listdir(userdata_dir):
+    # If no userdata directory, nothing to generate
+    if not os.path.isdir(userdata_dir):
+        _LOGGER.info("No 'userdata' directory found at %s; nothing to generate.", userdata_dir)
+        return
+
+    # Iterate over all files in a deterministic order
+    for filename in sorted(os.listdir(userdata_dir)):
+        full_path = os.path.join(userdata_dir, filename)
+        if not os.path.isfile(full_path):
+            continue
         if "mocked" in filename:
             continue
         if filename.endswith(".json"):
             # Construct the full paths for the base and new fixtures
-            base_fixture_path = os.path.join(userdata_dir, filename)
+            base_fixture_path = full_path
🧹 Nitpick comments (2)
airos/airos8.py (1)

271-272: Prefer class-qualified call for clarity

Now that derived_data is static, calling it via the class is clearer and avoids any confusion about binding semantics.

Apply this diff:

-                        adjusted_json = self.derived_data(response_json)
+                        adjusted_json = AirOS.derived_data(response_json)
script/generate_ha_fixture.py (1)

45-47: Minor: use json.load for files

json.load(source) is simpler and slightly more efficient than reading then json.loads.

Apply this diff:

-                with open(base_fixture_path, encoding="utf-8") as source:
-                    source_data = json.loads(source.read())
+                with open(base_fixture_path, encoding="utf-8") as source:
+                    source_data = json.load(source)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d0a247a and 3880dad.

📒 Files selected for processing (4)
  • .pre-commit-config.yaml (1 hunks)
  • airos/airos8.py (1 hunks)
  • script/generate_ha_fixture.py (1 hunks)
  • script/mashumaro-step-debug.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • script/mashumaro-step-debug.py
  • .pre-commit-config.yaml
🧰 Additional context used
🧬 Code Graph Analysis (2)
script/generate_ha_fixture.py (3)
airos/airos8.py (2)
  • derived_data (197-248)
  • AirOS (26-386)
tests/test_airos8.py (2)
  • test_derived_data_no_interfaces_key (106-110)
  • test_derived_data_no_br0_eth0_ath0 (114-124)
airos/exceptions.py (2)
  • AirOSDataMissingError (16-17)
  • AirOSKeyDataMissingError (20-21)
airos/airos8.py (3)
airos/data.py (3)
  • AirOSDataClass (107-110)
  • Derived (543-555)
  • AirOS8Data (559-576)
tests/test_airos8.py (2)
  • test_derived_data_no_interfaces_key (106-110)
  • test_derived_data_no_br0_eth0_ath0 (114-124)
airos/exceptions.py (1)
  • AirOSDataMissingError (16-17)
🔇 Additional comments (2)
airos/airos8.py (1)

196-197: derived_data staticmethod verified — all call sites pass a single argument

Conversion to @staticmethod is appropriate and verified: I scanned the repository and all usages pass exactly one argument.

  • airos/airos8.py:197 — definition
  • airos/airos8.py:271 — self.derived_data(response_json)
  • script/generate_ha_fixture.py:48 — AirOS.derived_data(source_data)
  • script/mashumaro-step-debug.py:76 — AirOS.derived_data(data)
  • tests/test_airos8.py:110 — airos_device.derived_data({})
  • tests/test_airos8.py:122 — airos_device.derived_data(fixture_data)
script/generate_ha_fixture.py (1)

48-49: Updated call aligns with new staticmethod signature

Switching to AirOS.derived_data(source_data) matches the new one-arg static method. Downstream deserialization remains correct.

@coderabbitai coderabbitai bot mentioned this pull request Oct 11, 2025
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