Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Support XML conversion for RESTful sensors #31809
Many devices continue to use XML for RESTful
This change implements converting XML output to
Type of change
Example entry for
Many devices continue to use XML for RESTful APIs. Interfacing with these APIs requires custom integrations or command line fork()/exec() overhead which many of these devices can work with as if they were JSON using xmltojson via this spec: https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html This change implements converting XML output to JSON via xmltojson so it can work with the existing rest sensor component. As the attributes that usually need to be scraped are deeper in the document support for passing in a template to find the JSON attributes that have been added. JSON APIs that do not have their attributes at the top level can also benefit from this change.
@@ Coverage Diff @@ ## dev #31809 +/- ## ========================================== - Coverage 94.68% 94.66% -0.03% ========================================== Files 763 763 Lines 55128 55193 +65 ========================================== + Hits 52197 52246 +49 - Misses 2931 2947 +16
We should not have a template generate JSON. So please drop the
For the XML support, let's not make it an option and just do it. If the response content type is XML, we parse the XML to JSON.
On a side note: the Rest component should really allow specifying 1 data source and multiple sensors/binary sensors on top of it using the DataUpdateCoordinator. Something like this:
rest: - resource: http://example.com/api binary_sensors: - resource: /is_on # relative to parent
I’m using json_attributes_template to specify the location in the JSON to scrape attributes since at times they are not at the top level. Can you suggest another method of doing this?
I could switch to jsonpath instead as it’s a bit more flexible and already being used in other places.
Will do on the auto switch xml. Likely looking for text/xml or .xml as the path in the url instead of having to specify