J. Nick Koston
5a609c34bb
Fix blocking I/O in the event loop when loading timezones ( #117721 )
2024-05-20 11:06:03 +02:00
rlippmann
1120246194
Deprecate relative_time() in favor of time_since() and time_until() ( #111177 )
...
* add time_since/time_until. add deprecation of relative_time
* fix merge conflicts
* Apply suggestions from code review
* Update homeassistant/helpers/template.py
* Update homeassistant/helpers/template.py
* Update homeassistant/helpers/template.py
---------
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-04-24 11:13:07 +02:00
Sid
8e98ba7312
Add first batch of Ruff PYI rules ( #115100 )
...
Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
2024-04-07 11:30:50 -10:00
Marc Mueller
443bfee16d
Replace partial annotations ( #114177 )
2024-03-28 18:33:39 +01:00
Joost Lekkerkerker
6bb4e7d62c
Bump ruff to 0.3.4 ( #112690 )
...
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
Marc Mueller
19ab3d6daf
Add empty line after module docstring [helpers + other] ( #112707 )
2024-03-08 10:36:11 -05:00
J. Nick Koston
52e90b32df
Avoid many replace calls in find_next_time_expression_time ( #108273 )
2024-01-18 08:44:40 +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
67039e0f26
Remove monotonic_time_coarse datetime helper ( #104892 )
2023-12-04 09:10:13 +01:00
Ville Skyttä
2399cd283a
Python 3.10 support cleanups ( #98640 )
2023-08-21 19:14:07 +02:00
Franck Nijhof
3e85a29b86
Move overlapping pylint rules to ruff, disable mypy overlap ( #94359 )
2023-06-27 17:42:46 +02: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
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
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
J. Nick Koston
1589c06203
Significantly reduce clock_gettime syscalls on platforms with broken vdso ( #81257 )
2022-10-31 09:35:08 -04:00
Kevin Stillhammer
90e5d69184
Add template as_timedelta ( #71801 )
2022-05-23 19:32:22 +02:00
J. Nick Koston
4e9bc9eaff
Small cleanups to find_next_time_expression and addition of tests ( #71845 )
2022-05-14 12:13:32 -07:00
J. Nick Koston
ebce5660e3
Sync event timed_fired and the context ulid time ( #71854 )
2022-05-14 12:12:08 -07:00
Marc Mueller
d8f167bbac
Remove `backports.zoneinfo` dependency ( #65069 )
2022-01-27 09:59:27 -08:00
Marvin Wichmann
707fe67c00
Move StrEnum to homeassistant.backports and move Platform to homeassistant.const ( #60880 )
...
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-12-03 09:31:17 +01:00
Franck Nijhof
c8b0a3b667
Revert "Move Platform StrEnum to const" ( #60875 )
2021-12-02 14:19:08 -08:00
Franck Nijhof
6e220d5d17
Move Platform StrEnum to const ( #60857 )
2021-12-02 22:30:52 +01:00
J. Nick Koston
1cd9be7538
Fix recursive limit in find_next_time_expression_time ( #58914 )
...
* Fix recursive limit in find_next_time_expression_time
* Add test case
* Update test_event.py
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-02 00:11:17 +01:00
Otto Winter
a9c0f89c09
Fix find_next_time_expression_time ( #58894 )
...
* Better tests
* Fix find_next_time_expression_time
* Add tests for Nov 7th 2021, Chicago transtion
* Update event tests
* Update test_event.py
* small performance improvement
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-01 17:45:13 +01:00
Marc Mueller
7af67d34cf
Use assignment expressions 01 ( #56394 )
2021-09-18 13:31:35 -10:00
Daniel Hjelseth Høyer
fbad453c89
Pylint 2.9.3 ( #52972 )
...
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2021-07-14 21:44:57 -07:00
Erik Montnemery
15e2c6d7dc
Fix typing for dt_util as_timestamp ( #50886 )
...
* Fix typing for dt_util::as_timestamp
* Apply suggestions from code review
2021-05-22 09:34:49 +02:00
Ruslan Sayfutdinov
de5472403b
Use mypy-friendly conditional import for zoneinfo ( #50444 )
2021-05-13 22:36:49 -07:00
Paul Ganssle
efa5c59559
Replace hand-rolled binary search with bisect_left ( #50410 )
...
The `bisect` module exposes a `bisect_left` function which does
basically what the bulk of `_lower_bound` does. From my tests, it is
slightly faster (~5%) in the probably common ideal case where `arr` is short.
In the worst case scenario, `bisect.bisect_left` is *much* faster.
```
>>> arr = list(range(60))
>>> cmp = 59
>>> %timeit _lower_bound(arr, cmp)
736 ns ± 6.24 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
>>> %timeit bisect_lower_bound(arr, cmp)
290 ns ± 7.77 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
```
I doubt this is a huge bottleneck or anything, but I think it's a bit
more readable, and it's more efficient, so it seems like it's mostly a
win.
This commit *will* add a new unconditional import for `bisect` when
importing `util.dt`, and `bisect` is not currently imported for any of
the standard library modules. It is possible to make this conditional by
placing `import bisect` in the _lower_bound function, or in the function
it's nested in.
2021-05-11 08:18:20 -07:00
Paulus Schoutsen
f8584c3ded
Use zoneinfo instead of dateutil ( #50387 )
...
Co-authored-by: J. Nick Koston <nick@koston.org>
2021-05-10 08:32:29 -07:00
J. Nick Koston
bf2d40adfe
Migrate from pytz to python-dateutil ( #49643 )
...
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-05-07 22:46:26 -07:00
Franck Nijhof
6932cf9534
Use contextlib.suppress where possible ( #48189 )
2021-03-23 14:36:43 +01:00
Franck Nijhof
8a56dbf587
Add flake8 comprehensions checks to pre-commit & CI ( #48111 )
2021-03-19 13:41:09 +01:00
Marc Mueller
fabd73f08b
Update typing 03 ( #48015 )
2021-03-17 21:46:07 +01:00
Paulus Schoutsen
edf70e9f06
Make input_datetime better handle timezones ( #43396 )
...
* Make input_datetime better handle timezones
* Improve test coverage
* Apply suggestions from code review
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
* Revert change to time format
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-11-26 20:20:10 +01:00
J. Nick Koston
a9de9c62f1
Use native utc timezone for utcnow() ( #41727 )
...
This allows timezone operations to happen in C code instead
of the pure-python code of pytz
2020-10-12 17:43:21 -05:00
Dmitry
b106149588
Fix string parameter processing in parse_time_expression ( #41468 ) ( #41469 )
2020-10-09 11:48:49 +02:00
J. Nick Koston
42227c1c53
Improve the performance of dt_util.utcnow() ( #39145 )
2020-08-23 09:57:58 +02:00
Jelle Raaijmakers
ef254a1c3d
Round time values in get_age() to better approximate the actual age ( #37125 )
2020-07-09 11:19:38 -07:00
Ville Skyttä
b4404b071f
Pylint cleanups ( #35409 )
...
* Avoid some outer name redefinitions
* Remove unneeded directives
* Narrow directive scope
* Don't disable redefined-variable-type
2020-05-09 14:08:40 +03:00
Franck Nijhof
71a47fc80c
Enable pylint global-statement ( #33641 )
2020-04-04 20:10:55 +02:00
Ruslan Sayfutdinov
15b4975681
Use ciso8601 library to parse datetime faster ( #32128 )
2020-02-24 08:33:10 -08:00
Ville Skyttä
fa4fa30461
Various string cleanups ( #30435 )
...
* Remove some unnecessary string concatenations
* Replace some simple str.formats with f-strings
* Replace some string concatenations with f-strings
2020-01-03 14:47:06 +01:00
Ville Skyttä
e6388e186c
Remove unnecessary string literal concatenations ( #30360 )
2020-01-02 21:17:10 +02:00
Bas Nijholt
67c56c860d
Sort imports according to PEP8 for 'homeassistant' folder ( #29789 )
...
Components are already done
2019-12-09 16:42:10 +01:00
Ville Skyttä
761d7f21e9
Upgrade pylint ( #27279 )
...
* Upgrade pylint to 2.4.2 and astroid to 2.3.1
https://pylint.readthedocs.io/en/latest/whatsnew/2.4.html
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-1
https://pylint.readthedocs.io/en/latest/whatsnew/changelog.html#what-s-new-in-pylint-2-4-2
* unnecessary-comprehension fixes
* invalid-name fixes
* self-assigning-variable fixes
* Re-enable not-an-iterable
* used-before-assignment fix
* invalid-overridden-method fixes
* undefined-variable __class__ workarounds
https://github.com/PyCQA/pylint/issues/3090
* no-member false positive disabling
* Remove some no longer needed disables
* using-constant-test fix
* Disable import-outside-toplevel for now
* Disable some apparent no-value-for-parameter false positives
* invalid-overridden-method false positive disables
https://github.com/PyCQA/pylint/issues/3150
* Fix unintentional Entity.force_update override in AfterShipSensor
2019-10-07 08:17:39 -07:00
Franck Nijhof
2f0eb07624
Migrate legacy typehints in core to PEP-526 ( #26403 )
...
* Migrate legacy typehints in core to PEP-526
* Fix one type
2019-09-03 20:36:04 -07:00
Franck Nijhof
decf13b948
Use literal string interpolation in core (f-strings) ( #26166 )
2019-08-23 09:53:33 -07:00
Paulus Schoutsen
620cb74050
Type
2019-07-31 13:08:31 -07:00