Use jsonpath-ng extended parser for JSON_PATHS#349
Conversation
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
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughJSON HTTP and MQTT powermeter modules upgrade from ChangesJSONPath Extended Syntax Adoption
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Review rate limit: 0/1 reviews remaining, refill in 35 minutes and 13 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/astrameter/powermeter/mqtt.py (1)
7-7: ⚡ Quick winAdd an MQTT regression test for extended JSONPath transforms.
Line 7 changes parser behavior, but
src/astrameter/powermeter/mqtt_test.pycurrently 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
📒 Files selected for processing (6)
CHANGELOG.mdREADME.mdconfig.ini.examplesrc/astrameter/powermeter/json_http.pysrc/astrameter/powermeter/json_http_test.pysrc/astrameter/powermeter/mqtt.py
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
Switches the JSON HTTP and MQTT powermeters from
jsonpath_ng.parsetojsonpath_ng.ext.parseso users can sanitize values inside the path expression withsplitorsubextensions. This lets sources like openHAB'sNumber:Poweritems (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
Documentation
Tests