Commit Graph

54 Commits (b2ceb2043b00545414d09b12f264f6baa61402fe)

Author SHA1 Message Date
J. Nick Koston 03e3ebb238
Use json_loads by default for the aiohttp helper () 2022-07-14 15:37:12 -05:00
J. Nick Koston da027fa390
JSON serialize NamedTuple subclasses with aiohttp () 2022-07-11 14:46:55 -07:00
J. Nick Koston 8b067e83f7
Initial orjson support take 3 ()
* Initial orjson support take 2

Still need to work out problem building wheels

--

Redux of  /  Now possible since the following is solved:
 (comment)

This implements orjson where we use our default encoder.  This does not implement orjson where `ExtendedJSONEncoder` is used as these areas tend to be called far less frequently.  If its desired, this could be done in a followup, but it seemed like a case of diminishing returns (except maybe for large diagnostics files, or traces, but those are not expected to be downloaded frequently).

Areas where this makes a perceptible difference:
- Anything that subscribes to entities (Initial subscribe_entities payload)
- Initial download of registries on first connection / restore
- History queries
- Saving states to the database
- Large logbook queries
- Anything that subscribes to events (appdaemon)

Cavets:
orjson supports serializing dataclasses natively (and much faster) which
eliminates the need to implement `as_dict` in many places
when the data is already in a dataclass. This works
well as long as all the data in the dataclass can also
be serialized. I audited all places where we have an `as_dict`
for a dataclass and found only backups needs to be adjusted (support for `Path` needed to be added for backups).  I was a little bit worried about `SensorExtraStoredData` with `Decimal` but it all seems to work out from since it converts it before it gets to the json encoding cc @dgomes

If it turns out to be a problem we can disable this
with option |= [orjson.OPT_PASSTHROUGH_DATACLASS](https://github.com/ijl/orjson#opt_passthrough_dataclass) and it
will fallback to `as_dict`

Its quite impressive for history queries
<img width="1271" alt="Screen_Shot_2022-05-30_at_23_46_30" src="https://user-images.githubusercontent.com/663432/171145699-661ad9db-d91d-4b2d-9c1a-9d7866c03a73.png">

* use for views as well

* handle UnicodeEncodeError

* tweak

* DRY

* DRY

* not needed

* fix tests

* Update tests/components/http/test_view.py

* Update tests/components/http/test_view.py

* black

* templates
2022-06-22 21:59:51 +02:00
J. Nick Koston c365454afb
Revert "Initial orjson support ()" ()
This was causing the wheels to fail to build. We need
to workout why when we don't have release pressure

This reverts commit d9d22a9556.
2022-05-31 13:51:55 -07:00
J. Nick Koston d9d22a9556
Initial orjson support () 2022-05-31 12:18:11 -07:00
Marc Mueller bfb1abd3a2
Add type ignore error codes [helpers] () 2022-02-18 11:31:37 +01:00
Ruslan Sayfutdinov 55f4962c06
Fix pylint plugin which checks relative imports () 2021-12-23 11:14:47 -08:00
J. Nick Koston 10d6247fee
Bump to aiohttp 3.8.0 () 2021-11-04 10:07:50 -05:00
Marc Mueller 238b488642
Use assignment expressions 03 () 2021-10-17 20:08:11 +02:00
Marc Mueller 77ee72cbb9
Import Callable from collections.abc (1) () 2021-09-29 16:32:11 +02:00
Paulus Schoutsen ede7932a57
Protect our user agent ()
* Protect our user agent

* Fix expected error
2021-06-04 09:14:18 -07:00
Marc Mueller c07646db5d
Update typing syntax ()
* Update typing syntax

* Replace typing imports with ones from collections where possible

* Changes after review
2021-04-20 17:40:41 +02:00
J. Nick Koston 40450b9cfd
Detach aiohttp.ClientSession created by config entry setup on unload () 2021-04-09 10:14:33 -07:00
Franck Nijhof 38d14702fa
Remove HomeAssistantType alias from helpers () 2021-03-27 12:55:24 +01:00
Franck Nijhof 6932cf9534
Use contextlib.suppress where possible () 2021-03-23 14:36:43 +01:00
Marc Mueller 6fb2e63e49
Update typing 02 () 2021-03-17 18:34:19 +01:00
jlvaillant a50fba4e0b
more graceful shutdown in the presence of a proxy_stream () 2021-01-17 17:10:22 +01:00
J. Nick Koston 6822190772
Fix unmocked https in the test suite () 2020-10-25 07:16:23 -05:00
Philip Allgaier dde6305549
Cleanup unused loggers (components N-Z + tests) () 2020-10-16 21:24:08 -05:00
Franck Nijhof 1c2ebdf307
Upgrade black to 20.8b1 () 2020-08-27 13:56:20 +02:00
Paulus Schoutsen f49ce5d1b4
Protect loop set default executor ()
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-07-06 15:58:53 -07:00
Martin Hjelmare 2a120d9045
Patch aiohttp client session close ()
* Patch aiohttp client session close

* Add test

* Restore close regardless of auto_cleanup

* Close session instead of detaching and do not restore

* Delint test

* Add frame helper

* Use frame helper

* Test warning log when closing session

* Clean up

* Correct docstring

* Do not change shutdown

* Fix tests
2020-05-13 09:58:33 +02:00
Paulus Schoutsen 8f9467492d
Remove some passings of loop () 2020-04-30 21:34:51 -07:00
Paulus Schoutsen 7d8da47309
Revert "Use orjson to parse json faster ()" ()
This reverts commit 2365e2e8cf.
2020-02-25 21:07:16 +01:00
Ruslan Sayfutdinov 2365e2e8cf
Use orjson to parse json faster ()
* [recorder] Use orjson to parse json faster

* Remove from http manifest

* Bump to orjson 2.5.1

* Empty commit to trigger CI

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-02-25 10:20:51 -08:00
Bas Nijholt 67c56c860d Sort imports according to PEP8 for 'homeassistant' folder ()
Components are already done
2019-12-09 16:42:10 +01:00
Franck Nijhof 2f0eb07624 Migrate legacy typehints in core to PEP-526 ()
* Migrate legacy typehints in core to PEP-526

* Fix one type
2019-09-03 20:36:04 -07:00
Paulus Schoutsen 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Paulus Schoutsen f995ab9d54
Don't pass in loop ()
* Don't pass in loop

* Revert some changes

* Lint + Axis revert

* reinstate loop

* Fix a test

* Set loop

* Update camera.py

* Lint
2019-05-22 21:09:59 -07:00
ehendrix23 7862fdd27e Fix myq increasing number of network connections ()
* Fix for network issues

Fix for network issues

* Further changes to network connection

* websession is created in pymyq

websession is created in pymyq instead.
Added call on stop event to close web session.

* Updated requirements file

* Added comment

* Changed back to use aiohttp_client

* Cleanup closed sockets in aiohttp

Enable automatic cleanup of closed sockets in aiohttp client helper.

* Updated manifest & requirements

* Updated comment block
2019-04-10 14:24:12 -07:00
Ville Skyttä d45f25ce2c Add more type hints to helpers ()
* Add type hints to helpers.aiohttp_client

* Add type hints to helpers.area_registry
2019-02-07 13:34:14 -08:00
Paulus Schoutsen 64b4c8f43a
Fix deprecation warning () 2019-01-08 21:09:47 -08:00
Paulus Schoutsen 9ab8f78b19
Don't pass use_env=True () 2018-09-26 17:20:34 +02:00
Martin Mois 672fc61bb2 aiohttp.ClientSession gets proxy information from HTTP_PROXY/HTTPS_PROXY () 2018-09-26 08:43:09 +02:00
Pascal Vizeli f3dfc433c2 Fix aiohttp connection reset errors ()
* Fix aiohttp connection reset errors

* Update aiohttp_client.py

* Update aiohttp_client.py

* Update __init__.py

* Update mjpeg.py

* Update mjpeg.py

* Update ffmpeg.py

* Update ffmpeg.py

* Update ffmpeg.py

* Update proxy.py

* Update __init__.py

* Update aiohttp_client.py

* Update aiohttp_client.py

* Update proxy.py

* Update proxy.py

* Fix await inside coroutine

* Fix async syntax

* Lint
2018-07-23 14:36:36 +02:00
Paulus Schoutsen ad4cba70a0
Extract SSL context creation to helper ()
* Extract SSL context creation to helper

* Lint
2018-07-16 10:32:07 +02:00
Ville Skyttä b92350fb55 Lint cleanup ()
* Remove unneeded inline pylint disables

* Remove unneeded noqa's

* Use symbol names instead of message ids in inline pylint disables
2018-06-25 13:05:07 -04:00
Paulus Schoutsen 89a19c89a7 Fix aiohttp deprecation warnings ()
* Fix aiohttp deprecation warnings

* Fix Ring deprecation warning

* Lint
2018-03-15 21:49:49 +01:00
Paulus Schoutsen 6a5c7ef43f
Upgrade to aiohttp 3 ()
* Upgrade aiohttp to 3.0.6

* Fix tests

* Fix aiohttp client stream test

* Lint

* Remove drain
2018-03-05 13:28:41 -08:00
Paulus Schoutsen 67c49a7662
Add config flow for Hue ()
* Add config flow for Hue

* Upgrade to aiohue 0.2

* Fix tests

* Add tests

* Add aiohue to test requirements

* Bump aiohue dependency

* Lint

* Lint

* Fix aiohttp mock

* Lint

* Fix tests
2018-03-03 21:28:04 -08:00
Julius Mittenzwei 16cb7388ee Removing asyncio.coroutine syntax from HASS core ()
* changed asyncio.coroutine syntax to new async def/await

* removed py34 from tox environment

* reverted some changes within entity.py

* -

* reverted changes within bootstrap.py

* reverted changes within discovery.py

* switched decorators

* Reverted change within aiohttp_client.py

* reverted change within logging.py

* switched decorators

* Await lock properly

* removed asyncio.coroutine from test
2018-02-25 03:38:46 -08:00
Paulus Schoutsen 6cce934f72 Improve SSL certs used by aiohttp ()
* Improve SSL certs used by aiohttp

* Add certifi package

* Lint
2017-10-19 10:47:57 +02:00
Paulus Schoutsen ca54bbfcc9 RFC: Use bind_hass for helpers ()
* Add Helpers bind_hass functionality

* Update other helpers
2017-10-08 08:17:54 -07:00
Andrey Kupreychik c537770786 Close stream request once we end up with proxy ()
* Close stream request once we end up with proxy

* Update aiohttp_client.py

* Update aiohttp_client.py

* Removed trailing whitespace
2017-08-26 09:56:39 -07:00
Fabian Affolter 0863d50210 Fix typos ()
Add an optional extended description…
2017-06-08 15:53:12 +02:00
Paulus Schoutsen 8c97bccaaa Handle aiohttp task cancellation better () 2017-03-31 11:55:22 +02:00
Paulus Schoutsen 714b516176 aiohttp 2 ()
* Upgrade aiohttp2

* Fix resource caching

* Fix helpers.aiohttp_client

* Lint

* Use static path for api error_log

* Fix ClientErrors import

* Remove not needed DisconnectError

* Remove releasing responses code

* Add timeout if stream starts non responding

* More async_aiohttp_proxy_stream cleanup

* Fix references to ClientError

* Fix fingerprinting

* Fix aiohttp stream tests

* Rename aiohttp_proxy_stream

* Remove impossible darksky test

* Fix sleepiq requests escaping mocker

* Lint

* Remove deprecated parameter

* Break up aiohttp_proxy_stream in 2 methods

* Lint

* Upgrade to aiohttp 2.0.4

* Convert connector close to a callback

* Fix static fingerprinted links
2017-03-30 00:50:53 -07:00
Pascal Vizeli 41849eab06 Core cleanup: two stage shutdown ()
* Core cleanup: two stage shutdown

* fix spell

* fix

* add async logger to close

* change aiohttp to use CLOSE

* address paulus comments

* Fix tests

* Add unittest
2017-02-13 06:24:07 +01:00
Pascal Vizeli 92858554e6 Bugfix endless aiohttp streamreader () 2017-01-24 20:43:36 +01:00
Pascal Vizeli 8da398c0bd Proxy aiohttp websession / more rebust. () 2017-01-19 09:55:27 -08:00