TL;DR: jump to the “Proposal” at the end; all the rest is reasoning about why I want to make this change, since usually any change in OS code comes with many backlashes lol
After having some hard time trying to “simply” read a public JSON API, I’m “happy” to report that it’s not exactly easy to test out JSON-pathing to use it with the REST sensor :))
Since logging doesn’t help (“JSON result was not a dictionary or list with 0th element a dictionary”, without stating WHAT it’s getting), I copied the full API output (which isn’t also exactly obvious if you never touched the logger
component) into jsonpath.com and started playing around there.
Through the magic of bad SEO (at least bad for users haha), I ended up on SmartBear’s (who??) JSONPath docs, which mention &&
and ||
support in filter expressions. That also works on jsonpath.com, so I just used it in HA and… well, you know, I’ve already wrote the error I was getting
I did some digging on the source code and the current lib in use is jsonpath
, which does not support those extensions (since much later on I ended up in the actual “official” docs and there are no logical operators there). However, jsonpath-ng
does (albeit with a single &
… extensions).
The proposal
Those libs should be swapped, and it should be documented in the REST docs that some extensions are (now) supported, linking to jsonpath-ng
’s docs. I think I can send a PR, but I would need some guidance if anyone can kindly help me out
- disclaimer: last time I wrote Python was 6 years ago, I’m a seasoned PHP/JS developer (sorry)
- where should I go about adding this new dependency? I don’t see
jsonpath
atrequirements.txt
… Is that pre-bundled with Python, or required somewhere else? - is there any standard on how to document features added after a given version?