Commit Graph

809 Commits (a5f70dec967428d26e0be3ce2495588b7542a7b5)

Author SHA1 Message Date
J. Nick Koston f59268b2ee
Include filename in exception when loading a json file fails (#111802)
* Include filename in exception when loading a json file fails

* fix
2024-02-29 10:30:29 -05:00
J. Nick Koston cfe478245f
Migrate gather_with_limited_concurrency to use create_eager_task (#111565) 2024-02-26 16:31:52 -10:00
J. Nick Koston 67e356904b
Add support for eager tasks (#111425)
* Add support for eager tasks

python 3.12 supports eager tasks

reading:
https://docs.python.org/3/library/asyncio-task.html#eager-task-factory
https://github.com/python/cpython/issues/97696

There are lots of places were we are unlikely to suspend, but we might
suspend so creating a task makes sense

* reduce

* revert entity

* revert

* coverage

* coverage

* coverage

* coverage

* fix test
2024-02-26 11:36:46 -05:00
J. Nick Koston 5d421e249f
YAML loader performance improvements (#111199)
* YAML loader performance improvements

- Cache the name of the loader since we call it multiple
  times for every line

- Add a fast path for scalar tags since they are the
  most common

* Update homeassistant/util/yaml/loader.py

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>

* remove unreachable code

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-02-23 13:37:09 -05:00
Erik Montnemery 49a99559c7
Remove lru cache size limit of TemperatureConverter (#109726) 2024-02-05 20:21:04 +01:00
Marc Mueller cd0ee98dba
Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
J. Nick Koston 582d6968b2
Avoid de/recode of bytes to string to bytes when writing json files (#109348) 2024-02-02 09:02:26 +01:00
J. Nick Koston 155499fafe
Load json file as binary instead of decoding to string (#109351) 2024-02-02 09:00:46 +01:00
J. Nick Koston 8afcd53af6
Restore support for packages being installed from urls with fragments (#109267) 2024-02-01 08:56:57 +01:00
Robert Resch b409933d19
Add DurationConverter (#108865)
* Add DurationConverter

* Update withings snapshots

* Add sensor test

* Fix tests

* Update snapshots after #108902 was merged
2024-01-30 23:08:12 +01:00
Joakim Plate cece117c93
Flow rate unit conversions and device class (#106077)
* Add volume flow rate conversions

* Add missing translations

* Adjust liter unit and add gallons per minute

* Adjust to min instead of m for minutes

* Add matching class for number

* Add some tests for number and sensor platform

* Add deprecated constants

* Add explicit list of flow rate for check

This reverts commit 105171af31.
2024-01-30 15:01:08 +01:00
Erik Montnemery 1cb5bbf865
Fix empty files included by !include_dir_named (#108489)
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-01-20 15:12:32 +01:00
Marc Mueller afcb7a26cd
Enable strict typing for config (#108023) 2024-01-18 09:20:19 +01:00
J. Nick Koston 52e90b32df
Avoid many replace calls in find_next_time_expression_time (#108273) 2024-01-18 08:44:40 +01:00
Pedro Lamas 6cab4486f7
Fix loading empty yaml files with include_dir_named (#107853) 2024-01-16 10:23:04 +01:00
Marc Mueller a9420bf05a
Enable strict typing for ios (#107382) 2024-01-12 14:43:17 +01:00
J. Nick Koston 1e4d10efe1
Add caching to the distance calculation utility (#107626) 2024-01-08 21:51:56 -10:00
J. Nick Koston 69307374f4
Signficantly reduce executor contention during bootstrap (#107312)
* Signficantly reduce executor contention during bootstrap

At startup we have a thundering herd wanting to use the executor
to load manifiest.json. Since we know which integrations we are
about to load in each resolver step, group the manifest loads
into single executor jobs by calling async_get_integrations on
the deps of the integrations after they are resolved.

In practice this reduced the number of executor jobs
by 80% during bootstrap

* merge

* naming

* tweak

* tweak

* not enough contention to be worth it there

* refactor to avoid waiting

* refactor to avoid waiting

* tweaks

* tweaks

* tweak

* background is fine

* comment
2024-01-07 22:55:40 -05:00
J. Nick Koston 75d591593d
Remove calls to distribution and legacy zip support from package util (#107427) 2024-01-07 07:39:48 -10:00
Marc Mueller 43fa51b696
Enable strict typing for blueprint (#106887) 2024-01-02 20:48:51 +01:00
Erik Montnemery 8f9bd75a36
Enable strict typing of date_time (#106868)
* Enable strict typing of date_time

* Fix parse_datetime

* Add test

* Add comments

* Update tests/util/test_dt.py

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
2024-01-02 13:57:25 +01:00
J. Nick Koston a4f0c84457
Reduce duplicate code in json_loads (#106859) 2024-01-01 20:25:23 -10:00
Ville Skyttä 24b1e01d71
Update Ruff to 0.1.8, avoid linter/formatter conflicts (#106080)
* Disable Ruff rules that may conflict with the formatter

* Upgrade Ruff to 0.1.8

- https://github.com/astral-sh/ruff/releases/tag/v0.1.7
- https://github.com/astral-sh/ruff/releases/tag/v0.1.8

* Format with Ruff 0.1.8
2023-12-20 23:55:09 +01:00
Erik Montnemery 0c2485bc03
Freeze integration entity descriptions (#105984)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-12-18 16:28:13 -10:00
Marc Mueller b671de8942
Improve logging util typing (#105968) 2023-12-18 14:54:12 +01:00
Marc Mueller aac02d7b84
Add first TypeVarTuple annotations (#105379) 2023-12-18 00:38:07 +01:00
J. Nick Koston 47f8e08261
Reduce overhead to connect dispatcher (#105715)
Reduce overhead connect dispatcher

- We tend to have 1000s (or 10000s) of connected dispatchers which
  makes these prime targets to reduce overhead/memory

- Instead of creating new functions to wrap log exceptions each time
  use partials which reuses the function body and only create new
  arguments

Previous optimizations #103307 #93602
2023-12-16 10:16:58 +01:00
Erik Montnemery 22c3847c0e
Allow inheriting `FrozenOrThawed` with custom init (#105624) 2023-12-13 10:13:34 +01:00
Erik Montnemery 5bd0833f49
Improve FrozenOrThawed (#105541) 2023-12-12 21:19:41 +01:00
Erik Montnemery d4cf049016
Remove unneeded class _EntityDescriptionBase (#105518) 2023-12-11 23:10:11 +01:00
Erik Montnemery dd338799d4
Make it possible to inherit EntityDescription in frozen and mutable dataclasses (#105211) 2023-12-11 20:00:55 +01:00
vexofp 885410bcfc
Prevent duplicate default SSLContext instances (#105348)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-12-09 11:30:12 -10:00
Erik Montnemery af715a4b9a
Add workaround for orjson not handling subclasses of str (#105314)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-12-08 18:13:34 +01:00
Erik Montnemery 5b55c7da5f
Remove logic converting empty or falsy YAML to empty dict (#103912)
* Correct logic converting empty YAML to empty dict

* Modify according to github comments

* Add load_yaml_dict helper

* Update check_config script

* Update tests
2023-12-05 18:08:11 +01:00
Erik Montnemery 5b59e043fa
Don't use deprecated_class decorator on deprecated YAML classes (#105063) 2023-12-05 11:36:26 +01:00
Erik Montnemery ae002e2f38
Remove breaks_in_ha_version from deprecated YAML classes (#105062) 2023-12-05 10:48:31 +01:00
Jan Bouwhuis e8475b9b33
Add scaling utils for brightness and fanspeed (#104753)
Co-authored-by: Robert Resch <robert@resch.dev>
2023-12-04 12:10:58 +01:00
Erik Montnemery db51a8e1f7
Allow passing breaks_in_ha_version to deprecation helper decorators (#104985) 2023-12-04 11:52:10 +01:00
J. Nick Koston 67039e0f26
Remove monotonic_time_coarse datetime helper (#104892) 2023-12-04 09:10:13 +01:00
Niccolò Maggioni 0232c8dcb0
Add temperature to the light color mode parameter fallbacks (#86026)
* Add color temperature to the color mode fallbacks

* Manually add ATTR_COLOR_TEMP since ATTR_COLOR_TEMP_KELVIN is pre-parsed

* Include the legacy ATTR_COLOR_TEMP attribute in the tests

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Add citation for McCamy's approximation formula

If still existing, also see page 3 of https://www.st.com/resource/en/application_note/an5638-how-correlated-color-temperature-is-calculated-by-vd6283-stmicroelectronics.pdf

* Update homeassistant/util/color.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-12-01 08:26:07 +01:00
Erik Montnemery 00e57ab9a4
Use deprecated_class decorator in deprecated YAML loader classes (#104835) 2023-11-30 22:43:34 +01:00
Erik Montnemery abc05451a2
Restore renamed yaml loader classes and warn when used (#104818) 2023-11-30 18:14:48 +01:00
Erik Montnemery 12902b8a68
Add NodeStrClass.__voluptuous_compile__ (#104808) 2023-11-30 17:45:27 +01:00
Aarni Koskela 706add4a57
Switch formatting from black to ruff-format (#102893)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-11-27 14:38:59 +01:00
Erik Montnemery 88698d8dfe
Fix docstring in yaml util (#104240) 2023-11-20 11:34:14 +01:00
J. Nick Koston cc31d77205
Use ulid_now instead of ulid_at_timestamp if no timestamp is passed (#104226)
* Use ulid_now instead of ulid_at_timestamp if no timestamp is passed

ulid_now is slightly faster than ulid_at_timestamp

* tweak usage
2023-11-19 22:27:24 -05:00
Erik Montnemery f89194784d
Fix including yaml files with scalar values (#103914) 2023-11-13 15:23:50 +01:00
Erik Montnemery e49f6b41ee
Rename YAML loader classes (#103609) 2023-11-08 00:26:54 +01:00
Erik Montnemery c29b0cd05b
Correct line numbers in yaml node annotations (#103605) 2023-11-07 23:22:23 +01:00
Erik Montnemery 05deae09fc
Add file and line annotation to strings when loading yaml (#103586) 2023-11-07 17:10:15 +01:00
Erik Montnemery dff18b4a16
Rename `gather_with_concurrency` to `gather_with_limited_concurrency` (#102241)
* Rename gather_with_concurrency to gather_with_limited_concurrency

* Update test
2023-10-19 15:08:52 +02:00
Franck Nijhof 664e490cfa
Update base image to 2023.10.0 (#102126) 2023-10-18 19:11:41 +02:00
J. Nick Koston d0ba42283c
Use stdlib ip_address method in the network helper when compatible (#102019) 2023-10-15 21:24:49 -04:00
Erik Montnemery e6e190e7e2
Remove unused HideSensitiveDataFilter (#101689) 2023-10-09 12:02:52 +02:00
Erik Montnemery 4e98d39106
Use loader.async_suggest_report_issue in async util (#101516) 2023-10-06 19:57:43 +02:00
mbo18 b7914582db
Update homeassistant color (#101372) 2023-10-05 20:10:27 +02:00
Dave T 8626a4888c
Remove deprecated temperature conversion functions (#101204) 2023-10-04 06:04:23 +02:00
Dave T efca5ba554
Remove deprecated pressure conversion functions (#101347)
Remove deprecated pressure conversion utils
2023-10-04 06:03:32 +02:00
Dave T adf6d34d95
Remove deprecated speed conversion functions (#101350) 2023-10-04 06:01:45 +02:00
Dave T 8b7fae5200
Remove deprecated distance conversion functions (#101199) 2023-10-01 16:17:31 +02:00
Dave T a4a99ce957
Remove deprecated volume conversion functions (#101200) 2023-10-01 16:06:14 +02:00
Joost Lekkerkerker 59207be5f8
Add body_exists to MockRequest in aiohttp util (#100932)
* Add body_exists to MockRequest in aiohttp util

* Add body_exists to MockRequest in aiohttp util

* Add body_exists to MockRequest in aiohttp util
2023-09-26 17:52:29 +02:00
Marc Mueller 11e8bf0b9c
Update types packages (#100850) 2023-09-25 18:53:22 +02:00
Michael Hansen e69c88a0d2
Use aliases when listing pipeline languages (#99672) 2023-09-08 08:22:08 -04:00
Ville Skyttä 6399d74c15
Remove unnnecessary pylint configs from core (#98704) 2023-08-22 23:12:12 +02:00
Ville Skyttä 2399cd283a
Python 3.10 support cleanups (#98640) 2023-08-21 19:14:07 +02:00
Ville Skyttä 3094991236
Upgrade ruff to 0.0.285 (#98647) 2023-08-19 08:17:17 -04:00
Marc Mueller 54cbc85c13
Add types-Pillow dependency (#98266) 2023-08-13 11:57:46 -05:00
Marc Mueller 1daac46635
Replace deprecated pkg_resources with importlib.metadata (#97628) 2023-08-03 09:14:00 +02:00
Marc Mueller ad0873549d
Fix ssl DeprecationWarnings (#97623) 2023-08-03 09:11:41 +02:00
Franck Nijhof 30058297cf
Migrate backported StrEnum to built-in StrEnum (#97101) 2023-07-23 23:19:24 +02:00
Marc Mueller 77f38e33e5
Import names from typing instead of typing_extensions [3.11] (#97065) 2023-07-22 17:03:44 -05:00
J. Nick Koston 99def97ed9
Add cancel messages to core task cancelation (#96972) 2023-07-20 18:03:36 -05:00
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
Jan Bouwhuis b2388b74d9
Add mV as a unit for voltage and enable conversions (#84805)
fixes undefined
2022-12-30 12:51:05 +01:00
epenet 6261994fcf
Enable unit conversion for DATA_SIZE (#84699) 2022-12-29 09:58:15 +01:00
epenet 46e02ebaff
Enable unit conversion for DATA_RATE (#84698) 2022-12-28 21:49:00 +01:00
Franck Nijhof d4f69a3652
String formatting and max line length - Part 7 (#84532)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2022-12-27 11:18:56 +01:00
Marc Mueller 19acbf0d2a
Update types packages (#84381) 2022-12-21 19:15:55 +01:00
epenet d6fc2d9452
Prevent use of deprecated units (#83384)
* Prevent use of deprecated units

* Adjust obsolete util

* More units

* Add FREQUENCY

* Adjust pylint ignore

* Add ELECTRIC (current/potential)

* Add TIME

* Adjust units
2022-12-21 15:24:11 +01:00
Michaël Arnauts 7142b4ecac
Fixes some grammar mistakes (#84283) 2022-12-20 11:10:31 +01:00
epenet f4c13645d2
Add support for CCF volume unit (#84029) 2022-12-19 14:57:04 +01:00
epenet 4a848e8222
Add stones to mass units (#83933) 2022-12-13 17:35:14 +01:00
Marc Mueller 0e95875912
Improve ignore_variance typing (#83927) 2022-12-13 15:22:23 +01:00
epenet 583b4aef07
Enable automatic conversion for pressures (#83525)
* Enable automatic conversion between bar and psi

* Fix tests

* Fix mazda tests

* Fix oncue tests

* Adjust US pressures

* Adjust metric pressures

* Adjust tests

* Adjust tests
2022-12-12 12:42:35 +01:00
epenet b172abaeeb
Add new atmospheric pressure device class (#83455)
* Add new atmospheric pressure device class

* Translations

* Automatic conversion

* Convert all pressure units
2022-12-09 08:02:53 +01:00
epenet 91d6d620c2
Use new unit enums in alexa (#83409)
* Use new unit enums in alexa

* Adjust for mypy
2022-12-06 17:31:40 +01:00
epenet eb13f2b724
Use UnitOfVolume in unit conversion (#83292) 2022-12-05 16:56:05 +01:00
epenet 4ad9633dfb
Use new unit enums in weather entity (#82937) 2022-11-29 18:10:31 +01:00
epenet dd960c4e62
Add precipitation device class (#81145) 2022-11-18 12:41:33 +01:00
Aarni Koskela 8038485ca4
Use partition instead of split where possible in core (#81806) 2022-11-15 21:45:48 +01:00
Aarni Koskela fa9a51e528
Use os.path.dirname() for getting the directory name of a path (#81504) 2022-11-14 15:21:35 +01:00
Marc Mueller 0c8eeaa643
Update mypy to 0.990 (#81783)
* Update mypy to 0.990

* Remove type ignore - overriding attr with property (13475)

* Remove type ignores - hasattr (13544)

* Adjust type ignore - assignment (13549)

* New error code - type-abstract (13785)

* Disable annotation-unchecked (13851)
2022-11-08 14:41:39 +01:00
J. Nick Koston 1589c06203
Significantly reduce clock_gettime syscalls on platforms with broken vdso (#81257) 2022-10-31 09:35:08 -04:00
epenet 2a2e097e17
Use unit enums in unit utilities (#81030) 2022-10-26 20:47:17 +02:00
epenet 842cb18d39
Migrate energy units to an enum (#80998) 2022-10-26 13:56:51 +02:00
Erik Montnemery 352976fd1d
Add rules for converting volumes (#80951)
* Add rules for converting volumes

* Use SensorDeviceClass in new tests

* Tweak tests

* Update flo tests

* Update sensor tests
2022-10-26 10:29:33 +02:00
epenet 7838bb3ebe
Replace new PRECIPITATION_INTENSITY with enum (#80653) 2022-10-25 16:45:45 +02:00
Erik Montnemery 727eccfec4
Add GJ as supported unit for energy sensors (#80870)
* Add GJ as supported unit for energy sensors

* Update homeassistant/const.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2022-10-25 16:43:00 +02:00
epenet 0018939142
Adjust unit_system type hints (#80946) 2022-10-25 15:56:18 +02:00
Erik Montnemery b07e1281da
Add rules for converting speeds (#80943)
* Add rules for converting speeds

* Update metoffice wind speed sensors to prefer mph

* Don't convert speeds measured in knots
2022-10-25 14:53:59 +02:00