1
mirror of https://github.com/home-assistant/core synced 2024-10-01 05:30:36 +02:00
Commit Graph

636 Commits

Author SHA1 Message Date
Franck Nijhof
3e85a29b86
Move overlapping pylint rules to ruff, disable mypy overlap (#94359) 2023-06-27 17:42:46 +02:00
leranp
4a3f341444
Language codes for Hebrew (#93681)
* Language codes for Hebrew

There is 2 optional code for Hebrew:
he-IL is the new code
iw-IL is the old code , the google cloud STT for example is using the old code (iw)

* Update language.py

* Update test_language.py

* Update test_language.py

* Update test_language.py

* Simplify duplicate language check

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-05-30 22:27:32 -04:00
J. Nick Koston
2f1f32f0bb
Make unit converter use a factory to avoid looking up the ratios each conversion (#93706) 2023-05-29 20:50:40 +02:00
J. Nick Koston
780f9bcdc0
Fix shutdown being delayed for cancelling tasks (#93287) 2023-05-21 14:17:34 +02:00
J. Nick Koston
e593ceaaf2
Fix sslv2/sslv3 with unverified connections (#93037)
In #90191 we use the same ssl context for httpx now to avoid
a memory leak, but httpx previously allowed sslv2/sslv3 for
unverified connections

This reverts to the behavior before #90191
2023-05-13 20:16:11 -04:00
Erik Montnemery
9a70f47049
Teach UnitlessRatioConverter about ppm and ppb (#92989) 2023-05-12 16:46:37 +02:00
Michael Hansen
5d6ccd6a32
Allow "no" to match "nb" in language util (#92862)
* Allow "no" to match "nb"

* Adjust comparison for speed
2023-05-09 13:46:57 -05:00
Michael Hansen
b4bd3b97f8
Use order in preferred regions list (#91959)
* Use order in preferred regions list

* Use float for score (inf = exact match)
2023-04-24 14:12:38 -04:00
Michael Hansen
5075281add
Fix zh Hant/Hans (#91390)
* Fix zh Hant/Hans

* Fix comments
2023-04-24 16:55:08 +02:00
Michael Hansen
9fdc794b36
Prefer country over language family + MATCH_ALL (#91753)
* Prefer country over language family

* More test fixes
2023-04-20 13:55:26 -04:00
Erik Montnemery
0ecd23baee
Add WS API for debugging previous assist_pipeline runs (#91541)
* Add WS API for debugging previous assist_pipeline runs

* Improve typing
2023-04-17 11:48:02 -04:00
Michael
67c4de90f3
Add option to select list of accepted ssl ciphers in httpx client (#91389) 2023-04-15 09:32:30 -10:00
Michael Hansen
f0c625b2ad
Add language util (#91290)
* Add language util

* Add no match tests

* Update tests/util/test_language.py

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2023-04-12 20:27:09 -05:00
rlippmann
3a72054f93
Make dataclasses in HA core slotted (#91208) 2023-04-11 07:58:28 -10:00
Erik Montnemery
ead88cc3f8
Add preferred wind speed unit to unit systems (#90504)
* Add preferred wind speed unit to unit systems

* Tweak

* Update tests
2023-03-30 12:54:12 +02:00
J. Nick Koston
1f2268a878
Fix httpx client creating a new ssl context with each client (memory leak) (#90191)
* Fix httpx client creating a new ssl context with each client

While working on https://github.com/home-assistant/core/issues/83524
it was discovered that each new httpx client creates a new ssl context

f1157dbc41/httpx/_transports/default.py (L261)

If an ssl context is passed in creating a new one is avoided here

f1157dbc41/httpx/_config.py (L110)

This change makes httpx ssl no-verify behavior match aiohttp ssl no-verify
behavior

6da04694fd/aiohttp/connector.py (L892)

aiohttp solved this by wrapping the code that generates the ssl context
in an lru_cache

* compact
2023-03-24 08:40:47 +01:00
Jesse Moody
c4ee35570d
Update django github references to main instead of master branch. (#89951) 2023-03-20 10:27:55 +01:00
J. Nick Koston
87264d219a
Fix ssl context being recreated frequently in httpx (#89932)
* Fix ssl context being created every time in httpx

* its expensive, only do it once
2023-03-19 05:13:48 -04:00
J. Nick Koston
170a13302c
Reduce overhead to store context ids in the database (#88942) 2023-03-08 14:51:45 -10:00
Paulus Schoutsen
3f32c5d2ad
Yaml use dict (#88977)
* Use built-in dict instead of OrderedDict

* Use dict instead of OrderedDict in YAML
2023-03-01 12:29:57 -05:00
J. Nick Koston
8f6cfc25c0
Use ulid-transform for constructing ulids (#88939)
* Use ulid-transform for constructing ulids

A future PR will use the new library to reduce the storage
overhead of ulids in the database

* tweak

* tweak

* bump
2023-02-28 21:09:47 -05:00
J. Nick Koston
327edabb64
Fix checking if a package is installed on py3.11 (#88768)
pkg_resources is abandoned and we need to move away
from using it https://github.com/pypa/pkg_resources

In the mean time we need to keep it working. This fixes
a new exception in py3.11 when a module is not installed
which allows proper fallback to pkg_resources.Requirement.parse
when needed

```
2023-02-25 15:46:21.101 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
             ^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/config/config_entries.py", line 148, in post
    return await super().post(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/helpers/data_entry_flow.py", line 71, in post
    result = await self._flow_mgr.async_init(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 826, in async_init
    flow, result = await task
                   ^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 844, in _async_init
    flow = await self.async_create_flow(handler, context=context, data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 950, in async_create_flow
    await async_process_deps_reqs(self.hass, self._hass_config, integration)
  File "/Users/bdraco/home-assistant/homeassistant/setup.py", line 384, in async_process_deps_reqs
    await requirements.async_get_integration_with_requirements(
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 52, in async_get_integration_with_requirements
    return await manager.async_get_integration_with_requirements(domain)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 171, in async_get_integration_with_requirements
    await self._async_process_integration(integration, done)
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 186, in _async_process_integration
    await self.async_process_requirements(
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 252, in async_process_requirements
    await self._async_process_requirements(name, missing)
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 284, in _async_process_requirements
    installed, failures = await self.hass.async_add_executor_job(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/requirements.py", line 113, in _install_requirements_if_missing
    if pkg_util.is_installed(req) or _install_with_retry(req, kwargs):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/util/package.py", line 40, in is_installed
    pkg_resources.get_distribution(package)
  File "/opt/homebrew/lib/python3.11/site-packages/pkg_resources/__init__.py", line 478, in get_distribution
    dist = get_provider(dist)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pkg_resources/__init__.py", line 354, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
                                            ~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
``
2023-02-25 22:47:18 -05:00
epenet
aa20c902db
Add typed helpers and improve type hints in util/json (#88534)
* Add type hints to load_json

* Adjust ios

* Adjust nest

* Add use of load_json_array

* Add tests

* Adjust test patch

* Add test_load_json_os_error
2023-02-22 10:09:28 +01:00
J. Nick Koston
5bc0636905
Replace fire_coroutine_threadsafe with asyncio.run_coroutine_threadsafe (#88572)
fire_coroutine_threadsafe did not hold a reference to the asyncio
task which meant the task had the risk of being prematurely
garbage collected
2023-02-21 21:16:18 -05:00
Paulus Schoutsen
db3cd8e276
Fix danglin task for util.timeout (#88366)
Fix danglin task for util timeout
2023-02-18 00:11:35 -05:00
epenet
8c821c8969
Add JSON support to load_fixture (#88076)
* Add JSON support to load_fixture

* More tests

* Remove lru_cache on load_json
2023-02-16 19:40:47 +01:00
Jan Bouwhuis
57738fbb8c
Replace deprecated SSLContext constant PROTOCOL_TLS in mqtt (#88214)
Replace deprecated SSLContext constants
2023-02-16 13:01:28 -05:00
epenet
ba23816a0c
Inverse json import logic (#88099)
* Fix helpers and util

* Adjust components

* Move back errors

* Add report

* mypy

* mypy

* Assert deprecation messages

* Move test_json_loads_object

* Adjust tests

* Fix rebase

* Adjust pylint plugin

* Fix plugin

* Adjust references

* Adjust backup tests
2023-02-16 11:37:57 +01:00
epenet
a1b7842df2
Fix incorrect reference to json WriteError (#88161) 2023-02-15 10:40:26 +01:00
J. Nick Koston
03eea7bd3f
Avoid subprocess memory copy when c library supports posix_spawn (#87958)
* use posix spawn on alpine

* Avoid subprocess memory copy when c library supports posix_spawn

By default python 3.10 will use the fork() which has to
copy all the memory of the parent process (in our case
this can be huge since Home Assistant core can use
hundreds of megabytes of RAM). By using posix_spawn
this is avoided.

In python 3.11 vfork will also be available
https://github.com/python/cpython/issues/80004#issuecomment-1093810689
https://github.com/python/cpython/pull/11671 but we won't
always be able to use it and posix_spawn is considered safer
https://bugzilla.kernel.org/show_bug.cgi?id=215813#c14

The subprocess library doesn't know about musl though
even though it supports posix_spawn https://git.musl-libc.org/cgit/musl/log/src/process/posix_spawn.c
so we have to teach it since it only has checks for glibc
1b736838e6/Lib/subprocess.py (L745)

The constant is documented as being able to be flipped here:
https://docs.python.org/3/library/subprocess.html#disabling-use-of-vfork-or-posix-spawn

* Avoid subprocess memory copy when c library supports posix_spawn

By default python 3.10 will use the fork() which has to
copy memory of the parent process (in our case
this can be huge since Home Assistant core can use
hundreds of megabytes of RAM). By using posix_spawn
this is avoided and subprocess creation does not
get discernibly slow the larger the Home Assistant
python process grows.

In python 3.11 vfork will also be available
https://github.com/python/cpython/issues/80004#issuecomment-1093810689
https://github.com/python/cpython/pull/11671 but we won't
always be able to use it and posix_spawn is considered safer
https://bugzilla.kernel.org/show_bug.cgi?id=215813#c14

The subprocess library doesn't know about musl though
even though it supports posix_spawn https://git.musl-libc.org/cgit/musl/log/src/process/posix_spawn.c
so we have to teach it since it only has checks for glibc
1b736838e6/Lib/subprocess.py (L745)

The constant is documented as being able to be flipped here:
https://docs.python.org/3/library/subprocess.html#disabling-use-of-vfork-or-posix-spawn

* missed some

* adjust more tests

* coverage
2023-02-13 09:02:51 -05:00
J. Nick Koston
7aa1359c4a
Cache try_parse_enum (#87911) 2023-02-12 03:57:36 -06:00
J. Nick Koston
ea356ad260
Optimize fetching weekly/monthly/yearly statistics (#87747)
* Optimize fetching statistics

* speed up

* avoid double groupby

* avoid another loop

* tweak flow

* fixes

* tweak

* avoid a new dt object in the cache for week/month

* avoid a new dt object in the cache for week/month
2023-02-09 21:22:32 -05:00
Erik Montnemery
45ac8c515e
Update unit system unit conversions (#87632)
* Update unit system unit conversions

* Tweak tests
2023-02-08 10:52:54 +01:00
Erik Montnemery
4cecc28f8c
Update unit system unit conversions (#87621) 2023-02-07 13:19:11 +01:00
Marc Mueller
ea4e2ab4aa
Add Self typing (4) [mypy 1.0] (#87601) 2023-02-06 22:30:22 -06:00
Franck Nijhof
ca1a12898c
Enable Ruff D212 (#87347) 2023-02-03 23:08:48 +01:00
epenet
61734f04b8
Re-enable Ruff D418 (#87302) 2023-02-03 16:33:03 +01:00
Crisicus
934bb3e0c1
Fix an extra quote typo in the percentage util (#87161) 2023-02-02 19:59:08 -06:00
epenet
1225c5e97d
Add enum util (#87082)
* Add enum helper

* docstring

* Move to util

* Add use case
2023-02-01 15:00:27 +01:00
Franck Nijhof
3b5fd4bd06
Enable Ruff TRY004 (#86811) 2023-01-30 14:06:52 +01:00
epenet
561fc2d771
Remove deprecated unit system properties (#86643)
* Remove deprecated unit system properties

* Fix tests
2023-01-27 12:09:26 +01:00
SgtBatten
0ccab19d2c
Add Mega Joule as valid unit of energy (#86055)
* Add Mega joule

* Reorder valid energy types

Alphabetical

* Add Mega Joule

* Add Mega Joule as valid energy unit

* Add Mega Joule

* Add Mega Joule as a Unit of Measurement to Energy

* Update tests

* Update tests

* Update number docstring

Co-authored-by: Roving Ronin <108674933+Roving-Ronin@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-01-25 14:13:42 +01:00
Marc Mueller
8abce25948
Update Union typing (4) [Py310] (#86427) 2023-01-23 09:04:40 +01:00
Marc Mueller
45b4b0e990
Import ParamSpec from typing [Py310] (#86413)
* Import ParamSpec from typing [Py310]

* Update additional imports
2023-01-23 07:28:43 +01:00
Franck Nijhof
79b52a2b41
Stricter pylint message control (#86154) 2023-01-20 13:47:55 +01:00
Erik Montnemery
f93bbd55ba
Improve logging shutdown (#85812)
* Improve logging shutdown

* Update test
2023-01-17 20:06:25 +01:00
Erik Montnemery
b0d4b73874
Add unitless unit converter (#85694)
* Add unitless unit converter

* Adjust type hints

* Adjust tests

* Rename to UnitlessRatioConverter
2023-01-12 09:20:00 +01:00
Franck Nijhof
7adb8d5ddc
Code styling tweaks to core utils & YAML loader (#85433)
Code styling tweaks to core utils
2023-01-08 22:01:55 -08:00
J. Nick Koston
d81febd3f4
Small speed up to frequently called datetime functions (#85399) 2023-01-08 09:42:29 -10:00
SukramJ
005bc8994d
Add mA to SensorDeviceClass.CURRENT units (#84492)
fixes undefined
2022-12-30 13:55:14 +01:00