* Unused pylint suppression cleanups
* Remove outdated pylint bug references
* Add flake8-noqa config and note to run it every now and then
* Add codes to noqa's
* Unused noqa cleanups
* Update sensor.py
Some xml-result is passed via "application/xhtml+xml" instead of text/xml or application/xml. And then the xml structure is not parsed to json as expected. I changed it locally, but suggest to add thise here as well.
* Update homeassistant/components/rest/sensor.py
Fine for me as well, as it is working this way as well. But I would not see any disadvantage to convert everything, what is possible - a better scrape sensor this way. ;)
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
* add initial rest query params
* of course I didn't run black
* fix tests
* fix tests
* add test
* reformat
* add binary sensor test
* fix tests
* add one more test and fix switch
* should not have touched that
* if you don't pay attention once
* Rename BinarySensorDevice to BinarySensorEntity
* Tweak
* Move deprecation warning to __new__, add test
* Move deprecation warning back to __init__
* Move deprecation warning to __init_subclass
* Support XML conversion for RESTful sensors
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.
* Auto convert xml, change out the template for jsonpath
* Address review items and potentially unexpected normalize behavior with jsonpath
* Revert "Address review items and potentially unexpected normalize behavior with jsonpath"
This reverts commit fe9e179092.
* json_dict[0] turned out to be needed
* Make rest sensor a little bit more flexible and allow the response to be a list with 0th element being a dictionary
* Black formatter wanted a different formatting
* Added test case for a list response with dict as 0th element
* Fixed lint error - it thinks a + STRING is an avoidance of using % sequences for log messages; I generally prefer explicit + rather than string juxtaposition for combining string literals, but sounds like that's not the standard
* Fixed test case -- I added it to the wrong scenario and need to use the one with json_attrs.
* Fix digest auth rest sensors
* Refactor to use request()
* Fix black complaints
* Don't rename data variable
Don't rename the data variable, appears several other sensors have been coded to rely on it
* Fix tests
test_setup_missing_schema:
Change the exception to check for to PlatformNotReady. With the change away from prepared statements, we no longer get the MissingSchema error during setup - we get it when we attempt to call the endpoint. Since the result is PlatformNotReady, which is what we want, and the error log clearly contains a note that the schema is incorrect I think this is fine.
test_setup_failed_connect & test_setup_timeout:
These aren't checking for minimum config, and they're not invoking the correct method to have the default config filled in. Therefore I've just added the correct minimum config so these can continue to test what they're there to test.
test_update_request_exception:
Testing a request exception with the assert on line 404! Excellent. Anyway, we've moved from using the requests Session object to the requests.request function - so the patch needed to be altered to ensure the RequestException was raised.
* Remove no longer needed import
* Fix binary sensor test in same way