Commit graph

53 commits

Author SHA1 Message Date
epenet 1baa5c12c0
Fix rest schema (#81857) 2022-11-11 10:08:26 -06:00
epenet c585817e67
Adjust REST schema validation (#81723)
fixes undefined
2022-11-08 11:18:58 +01:00
epenet 934cec9778
Modernize rest switch tests (#81306)
* Adjust rest switch tests to use schema validation

* Simplify

* Use async_setup_component in tests

* Rewrite tests

* Add patch

* Remove patch

* Adjust mock
2022-11-07 13:08:05 +01:00
epenet a0ed91e30c
Add type hints to rest tests (#81304) 2022-10-31 15:30:29 +01:00
Erik Montnemery 146ff83a16
Migrate rest binary_sensor and switch to TemplateEntity (#73307) 2022-06-28 13:53:38 -07:00
J. Nick Koston dca4d3cd61
Significantly improve yaml load times when the C loader is available (#73337) 2022-06-13 08:44:46 -10:00
Erik Montnemery 5987266e56
Refactor template entity to allow reuse (#72753)
* Refactor template entity to allow reuse

* Fix schema and default name

* Add tests

* Update requirements

* Improve test

* Tweak TemplateSensor initializer

* Drop attributes and availability from TemplateEntity

* Use rest sensor for proof of concept

* Revert changes in SNMP sensor

* Don't set _attr_should_poll in mixin class

* Update requirements
2022-06-08 15:55:49 +02:00
epenet 831e2ace9c
Prettify yaml (tests) (#68891) 2022-03-30 11:26:08 +02:00
Simone Chemelli 969930b9c9
Remove debug print (#63460) 2022-01-05 15:34:33 +01:00
Robert Hillis d9788c2447
Use platform enums in rest tests (#62564) 2021-12-22 07:31:55 -05:00
Robert Hillis 1bd904b5b5
Use enums for rest tests (#62197)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-12-19 18:01:33 +01:00
Erik Montnemery aa36dde148
Correct rest sensor configured to generate timestamps (#61429) 2021-12-10 09:59:27 -08:00
Paulus Schoutsen 31153ac155
Move fixtures part 1 (#58902) 2021-11-01 20:47:05 -07:00
Chris Browet b1b782419b
Add REST sensor/binary_sensor/switch templated headers & params (#54426) 2021-10-29 16:36:47 -05:00
Ville Skyttä 5626cc4524
Use http.HTTPStatus in components/r* (#58288) 2021-10-23 20:53:39 +02:00
Chris Browet 1867d24b18
Add state_class support to Rest (#58026) 2021-10-22 13:48:13 -07:00
Paulus Schoutsen a4d9019ffc
Refactor persistent notification to no longer route all data via a service (#57157)
* Convert persistent notification tests to async

* Create/dismiss persistent notifications in exposed functions, not service calls

* Fix notify persistent_notification

* Remove setting up persistent_notification

* Drop more setups

* Empty methods

* Undeprecate sync methods because too big task

* Fix setup clearing notifications

* Fix a bunch of tests

* Fix more tests

* Uno mas

* Test persistent notification events

* Clean up stale comment

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-10-07 12:58:00 +02:00
Ville Skyttä 2730a27fd0
Use HTTPStatus instead of HTTP_* constants in various test mocks (#56543) 2021-10-01 15:52:45 -07:00
J. Nick Koston 30382c3dbe
Limit log spam from rest and include reason in platform retry (#48666)
- Each retry was logging the error again
- Now we set the cause of the PlatformNotReady to allow Home Assistant to log as needed
2021-04-04 20:26:18 -07:00
Franck Nijhof 5a2b5fe7c5
Yoda assertion style removed is (#48142) 2021-03-20 13:55:10 +01:00
J. Nick Koston dd56cc8010
Fix rest sensor data misalignment with multiple sensors (#48043)
If there were multiple rest data sources, the index needed
to be incremented by type instead of by data source/type
2021-03-17 22:47:42 +01:00
J. Nick Koston 2f3c2f5f4d
Add support for using a single endpoint for rest data (#46711) 2021-02-19 21:44:15 -08:00
Franck Nijhof 65cf2fcb6f
Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
J. Nick Koston dd0afc3b66
Create httpx helper to wrap a shared httpx.AsyncClient (#43877)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-12-09 17:18:57 +01:00
Jonas Lundberg a5279cc279
Upgrade respx to 0.16.2 (#43892)
* Bump respx to 0.16.2

* Align sensor tests to use new respx mock api
2020-12-04 04:27:25 +01:00
Moritz Schmitz von Hülst 434d39a5ea
Add initial rest query params (#42198)
* 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
2020-11-11 09:03:55 -10:00
J. Nick Koston 9e0043fb17
Fix rest sensors with resource templates (#42818) 2020-11-04 08:52:47 +01:00
Julian Engelhardt 5230ff6640
Rest test style (#42032) 2020-10-22 10:00:48 +02:00
J. Nick Koston ad6ce5fa83
Convert rest sensors to async using httpx (#41973) 2020-10-16 19:21:13 -05:00
springstan 6a7caad8dc
Use content type json constant (#40312) 2020-09-23 20:21:55 +02:00
springstan 0c077685b6
Use content type text plain constant (#40313) 2020-09-20 13:19:10 +02:00
jjlawren f01a0f9151
Allow separate URL for REST switch state (#39557) 2020-09-04 16:58:40 +02:00
J. Nick Koston 661b593db3
Support reloading the rest notify platform (#39527)
* Support reloading the rest notify platform

* update services.yaml

* fix conflict
2020-09-02 18:25:43 -05:00
Franck Nijhof 1c2ebdf307
Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02:00
J. Nick Koston 79f4b6eb6b
Cleanup the rest reload test to use the pytest requests_mock fixture (#39282) 2020-08-26 17:53:11 +02:00
J. Nick Koston 5018e53b33
Add the ability to reload the rest platforms from yaml (#39257)
* Add the ability to reload rest platforms from yaml

* Revert changes to notify as these will be done in another pass
2020-08-25 19:05:29 -05:00
Hedgehog57 fd1edf1bb6
Add resource_template to rest binary_sensor (#30703) 2020-06-23 15:08:55 -07:00
Paulus Schoutsen c33edbe5bb
Use TestCase.addCleanup (#36560) 2020-06-08 12:26:40 -07:00
Paulus Schoutsen 276f3afb00
Do async_setup_platform in background (#36244)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-05-31 22:18:30 -07:00
Paulus Schoutsen 2af984917e
Use asynctest-mock in most places (#35109)
* Use asynctest-mock in most places

* Fix broken patch in pilight
2020-05-03 11:27:19 -07:00
springstan fb8f8133a0
Use HTTP_INTERNAL_SERVER_ERROR constant (#33832) 2020-04-08 23:20:03 +02:00
J. Nick Koston 7f91501a36
Use a requests Session for rest sensors (#32463)
This avoids the ssl setup overhead for each request
2020-03-04 08:32:38 -08:00
J. Nick Koston 924c313c8a
Add application/xml as an XML to JSON auto converted mime type… (#32289)
* Resolves issue #32280
2020-03-01 23:22:01 -08:00
J. Nick Koston c7f128f286
Ensure rest sensors are marked unavailable when http requests… (#32309) 2020-02-28 11:41:41 -08:00
J. Nick Koston 096e7cceed
Support XML conversion for RESTful sensors (#31809)
* 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
2020-02-15 21:10:23 -08:00
Ville Skyttä 3e23a3a860
Add and use bunch of data size and rate related constants (#31781)
Also fix a few units to match the corresponding data.
2020-02-13 08:52:57 -08:00
Bas Nijholt 04225ba802 Sort imports according to PEP8 for rest (#29674) 2019-12-09 12:09:49 +01:00
gjbadros 5f1b0fb15c Allow rest sensor list responses (#28835)
* 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.
2019-11-26 22:10:58 +01:00
Tim McCormick 6c6a5c50a5 Fix digest auth rest sensors (#28153)
* 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
2019-11-25 23:22:11 -08:00
Fredrik Erlandsson 09d8a4204a Add support for resource_template for rest sensor (#27869)
* add support for resource_template

* fix tests

* updated tests and xor(CONF_RESOURCE_TEMPLATE, CONF_RESOURCE)
2019-10-22 22:43:28 -07:00