Skip to content

Use jsonpath-ng extended parser for JSON_PATHS#349

Merged
tomquist merged 3 commits into
developfrom
claude/jsonpath-value-parsing-ALxV8
May 3, 2026
Merged

Use jsonpath-ng extended parser for JSON_PATHS#349
tomquist merged 3 commits into
developfrom
claude/jsonpath-value-parsing-ALxV8

Conversation

@tomquist
Copy link
Copy Markdown
Owner

@tomquist tomquist commented May 3, 2026

Switches the JSON HTTP and MQTT powermeters from jsonpath_ng.parse to jsonpath_ng.ext.parse so users can sanitize values inside the path expression with split or sub extensions. This lets sources like openHAB's Number:Power items (which serialize as "331.74 W") be consumed without the float conversion blowing up on the unit suffix.

Refs #348

Summary by CodeRabbit

  • New Features

    • JSON HTTP and MQTT powermeters now support extracting numeric values with unit suffixes (e.g., "331.74 W") using enhanced JSONPath expressions with built-in transformations.
  • Documentation

    • Added examples and guidance for configuring JSONPath expressions to strip units and perform data transformations.
  • Tests

    • Added test coverage for unit-suffix stripping functionality.

Switches the JSON HTTP and MQTT powermeters from `jsonpath_ng.parse` to
`jsonpath_ng.ext.parse` so users can sanitize values inside the path
expression with `split` or `sub` extensions. This lets sources like
openHAB's `Number:Power` items (which serialize as `"331.74 W"`) be
consumed without the float conversion blowing up on the unit suffix.

Refs #348

https://claude.ai/code/session_015ezHVP9TLKv42AeEEwtboq
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

Warning

Rate limit exceeded

@tomquist has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 35 minutes and 13 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a6ede21-7f08-4969-84a1-31db006d8588

📥 Commits

Reviewing files that changed from the base of the PR and between 3c14058 and c198525.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • README.md

Walkthrough

JSON HTTP and MQTT powermeter modules upgrade from jsonpath_ng to jsonpath_ng.ext parser, enabling JSONPath expressions to include extended syntax for sanitizing unit-suffixed numeric strings (e.g., "331.74 W") before float conversion. Documentation and tests are updated accordingly.

Changes

JSONPath Extended Syntax Adoption

Layer / File(s) Summary
Dependency Import Updates
src/astrameter/powermeter/json_http.py, src/astrameter/powermeter/mqtt.py
Import statement changed from jsonpath_ng.parse to jsonpath_ng.ext.parse in both modules to enable extended JSONPath functionality.
Test Coverage
src/astrameter/powermeter/json_http_test.py
New test test_strips_unit_suffix_via_jsonpath_ext added that verifies extraction of numeric values from unit-suffixed strings using extended JSONPath expressions.
Documentation & Examples
CHANGELOG.md, README.md, config.ini.example
Changelog entry updated; README and example config files expanded with explanations of jsonpath-ng extended syntax and concrete examples showing split() and sub() transformations for stripping unit suffixes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically summarizes the main change: switching from the standard jsonpath-ng parser to the extended parser across JSON_PATHS implementations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/jsonpath-value-parsing-ALxV8

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Review rate limit: 0/1 reviews remaining, refill in 35 minutes and 13 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@tomquist tomquist marked this pull request as ready for review May 3, 2026 07:11
Copy link
Copy Markdown

@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 (1)
src/astrameter/powermeter/mqtt.py (1)

7-7: ⚡ Quick win

Add an MQTT regression test for extended JSONPath transforms.

Line 7 changes parser behavior, but src/astrameter/powermeter/mqtt_test.py currently only validates basic paths. Please add one case that strips a unit suffix (e.g. "331.74 W" via `sub(...)`) to lock in parity with JSON HTTP.

💡 Suggested test addition
--- a/src/astrameter/powermeter/mqtt_test.py
+++ b/src/astrameter/powermeter/mqtt_test.py
@@
 def test_extract_from_array():
     data = {
         "SML": {
             "measurements": [{"curr_w": 100.5}, {"curr_w": 200.75}, {"curr_w": 300}]
         }
     }
     assert extract_json_value(data, "$.SML.measurements[1].curr_w") == 200.75
+
+
+def test_extract_strips_unit_suffix_via_jsonpath_ext():
+    data = {"state": "331.74 W"}
+    assert extract_json_value(data, "$.state.`sub(/[^0-9.\\-]+$/, )`") == 331.74
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 720-725: Add a short note to the MQTT documentation under the
JSON_PATH/JSON_PATHS section clarifying that the same jsonpath-ng extended
syntax (jsonpath-ng.ext) and transforms shown for JSON_HTTP apply to MQTT as
well; update the MQTT section to mention JSON_PATH and JSON_PATHS support
chained extensions like `split(...)` and `sub(/regex/, replacement)` (use the
same examples shown for JSON_PATHS such as `$.state.\`split( , 0, -1)\`` and
`$.state.\`sub(/[^0-9.\-]+$/, )\``) so users know they can strip units or
massage values for MQTT payloads the same way.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50b725e1-9a6b-41de-9e1a-331d0571d0ad

📥 Commits

Reviewing files that changed from the base of the PR and between 3083fa8 and 3c14058.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • README.md
  • config.ini.example
  • src/astrameter/powermeter/json_http.py
  • src/astrameter/powermeter/json_http_test.py
  • src/astrameter/powermeter/mqtt.py

Comment thread README.md
claude added 2 commits May 3, 2026 07:16
The MQTT powermeter was switched to the extended parser in the previous
commit but its docs still pointed only to the base JSONPath spec; note
the ext support next to the existing JSONPath description so MQTT users
can also strip units / massage payloads inline.

https://claude.ai/code/session_015ezHVP9TLKv42AeEEwtboq
@tomquist tomquist merged commit a9abeae into develop May 3, 2026
13 checks passed
@tomquist tomquist deleted the claude/jsonpath-value-parsing-ALxV8 branch May 3, 2026 08:42
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.

2 participants