Commit Graph

48 Commits (50edc334dec634ef788ce72aca33b1454a32a3d7)

Author SHA1 Message Date
J. Nick Koston 368feec712
Refactor translations to reduce dict lookups (#107425)
* Refactor translations to reduce dict lookups

All of our cache lookups used:

`cache[language][O(component)][category]`

The cache was designed as

`cache[language][component][category][flatted_key]`

The lookups are now

`cache[language][category][O(component)]`

The cache is now stored as

`cache[language][category][component][flatted_key]`

This allows the catch fetch to avoid looking up
the category each loop

* already a set, and we do not mutate
2024-01-07 22:29:27 -05:00
Michael eb01998395
Add support for placeholders in entity name translations (#104453)
* add placeholder support to entity name translation

* add negativ tests

* make property also available via description

* fix doc string in translation_placeholders()

* fix detection of placeholder

* validate placeholders for localized strings

* add test

* Cache translation_placeholders property

* Make translation_placeholders uncondotionally return dict

* Fall back to unsubstituted name in case of mismatch

* Only replace failing translations with English

* Update snapshots

* Blow up on non stable releases

* Fix test

* Update entity.py

---------

Co-authored-by: Erik <erik@montnemery.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
2024-01-03 17:34:47 +01: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 84e74e4c74
Reverse component path (#104087)
* Reverse component path

* Update translations helper

* Fix

* Revert incorrect change of PLATFORM_FORMAT

* Fix use of PLATFORM_FORMAT in tts

* Fix ios
2023-12-05 08:43:58 +01:00
J. Nick Koston 3b8d99dcd8
Add __slots__ to translation cache (#100069) 2023-09-10 20:46:55 +02:00
Franck Nijhof f054de0ad5
Add support for service translations (#95984) 2023-07-11 15:52:12 +02:00
Franck Nijhof f32b7859b8
Restructure translations for entity components (#89702) 2023-03-16 12:16:08 +01:00
J. Nick Koston 8806c3dd20
Speed up loading non-english language translations (#88553)
Speed up loading non-english languages

We called async_get_integrations in each gathered task
instead of once for both languages we were loading
2023-02-21 21:18:33 -05:00
Franck Nijhof 06a35fb7db
Code styling tweaks to core helpers (#85441) 2023-01-08 13:44:09 -10:00
J. Nick Koston 194adcde9c
Drop ChainMap in translation cache (#85260) 2023-01-06 11:52:18 -10: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
Aarni Koskela 8038485ca4
Use partition instead of split where possible in core (#81806) 2022-11-15 21:45:48 +01:00
J. Nick Koston 61cc9f5288
Consolidate executor jobs when loading integration manifests (#75176) 2022-07-14 13:06:08 -07:00
J. Nick Koston a614ddca28
Support requesting translations for multiple integrations in a single request (#71979) 2022-05-17 01:23:11 -05:00
Marc Mueller 3b3e12aaa2
Fix `translation` typing (#66516) 2022-02-14 09:23:12 -08:00
Marc Mueller 240c9979c7
Move `disallow-any-generics` to mypy.ini (#63917) 2022-01-11 13:33:25 -08:00
Ville Skyttä 59809503d1
Various type hint related improvements (#54971)
* Avoid some implicit generic Anys

* Fix hassio discovery view type hints

* Fix http view result type in assert message
2021-08-21 13:58:49 +02:00
Ville Skyttä 470f2dd73f
Upgrade pyupgrade to 2.21.2, apply its changes (#52987) 2021-07-19 10:46:09 +02:00
Franck Nijhof 38d14702fa
Remove HomeAssistantType alias from helpers (#48400) 2021-03-27 12:55:24 +01:00
Marc Mueller 6fb2e63e49
Update typing 02 (#48014) 2021-03-17 18:34:19 +01:00
J. Nick Koston 94bf55e29b
Limit concurrency of async_get_integration to avoid creating extra threads (#43085)
* Limit concurrency of async_get_integration to avoid creating extra threads

Since async_get_integration is waiting on the disk most of the time
it would end up creating many new threads because the disk could
not deliver the data in time.

* pylint
2020-11-10 21:34:54 -10:00
J. Nick Koston c7f35b20fb
Make all translations cacheable (#42892) 2020-11-09 22:36:45 +01:00
J. Nick Koston 5ca4b4cd0f
Set the translations cache under the lock (#42470) 2020-10-27 22:02:38 +01:00
Franck Nijhof 1c2ebdf307
Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02:00
Joakim Sørensen 835f433cf7
Remove loading of legacy translations (#37021) 2020-06-23 10:58:11 +02:00
Paulus Schoutsen b3201523aa
Fix translation merging for custom components without translations (#35032) 2020-05-01 11:34:09 -07:00
Paulus Schoutsen e9ff1940d6
Translation fixes and tweaks (#34489)
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
2020-04-21 17:57:21 -07:00
Joakim Sørensen 730a257f3c
Rename translations dir for integrations (#34494) 2020-04-21 16:11:05 -07:00
Paulus Schoutsen 4720a7a891
Add foundation for state translations (#34443) 2020-04-19 20:35:49 -07:00
Paulus Schoutsen d10f5a48d4
Fix translations merging (#34417)
Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>
2020-04-19 12:37:44 -07:00
Paulus Schoutsen 98f1548f2d
Allow fetching translations by categories (#34329) 2020-04-18 17:13:13 -07:00
Paulus Schoutsen 94a3cec4bf
Take integration title from manifest if not translated (#34283) 2020-04-16 08:38:54 -07: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
Bas Nijholt 67c56c860d Sort imports according to PEP8 for 'homeassistant' folder (#29789)
Components are already done
2019-12-09 16:42:10 +01: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 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Joakim Plate 2fbbcafaed
Support config flow on custom components (#24946)
* Support populating list of flows from custom components

* Re-allow custom component config flows

* Add tests for custom component retrieval

* Don't crash view if no handler exist

* Use get_custom_components instead fo resolve_from_root

* Switch to using an event instead of lock

* Leave list of integrations as set

* The returned list is not guaranteed to be ordered

Backend uses a set to represent them.
2019-07-09 01:19:37 +02:00
Paulus Schoutsen 1e22c8daca
Automatically generate config flow list (#23802)
* Add config flow to manifest.json

* Still load config flows via config flow platform

* Fix typo

* Lint

* Update config_flows.py"

* Catch import error when setting up entry

* Lint

* Fix tests

* Fix imports

* Lint

* Fix Unifi tests

* Fix translation test

* Add homekit_controller config flow
2019-05-13 01:16:55 -07:00
Paulus Schoutsen fda483f482
Don't load component when fetching translations (#23196) 2019-04-18 11:11:43 -07:00
Paulus Schoutsen 3f69d0283d
Convert translation helper to use async_get_integration (#23054)
* Convert translation helper to use async_get_integration

* Simplify after comments

* Lint

* Fix typing

* Typo
2019-04-12 17:10:19 -07:00
uchagani c5f4aa0466 show which component is causing translation errors (#22340) 2019-03-23 23:06:55 -07:00
Paulus Schoutsen 9fd21d20ae
Fix loading translations for embedded platforms (#20122)
* Fix loading translations for embedded platforms

* Update doc string

* Lint
2019-01-15 16:06:04 -08:00
Ville Skyttä c9c707e368
Start type annotating/testing helpers (#17858)
* Add type hints to helpers.intent and location

* Test typing for helpers.icon, json, and typing

* Add type hints to helpers.state

* Add type hints to helpers.translation
2018-10-28 21:12:52 +02:00
Ville Skyttä 6f582dcf24 Lint cleanups (#15243)
* Remove some unused imports

* Fix a flake8 E271
2018-07-01 11:57:01 -04:00
Paulus Schoutsen 83d300fd11 Custom component loading cleanup (#14211)
* Clean up custom component loading

* Fix some tests

* Fix some stuff

* Make imports work again

* Fix tests

* Remove debug print

* Lint
2018-05-01 20:57:30 +02:00
Paulus Schoutsen fb1fafefab
Include all config flow translations with backend translations (#13394) 2018-03-22 12:21:33 -07:00
Adam Mills b434ffba2d Support serving of backend translations (#12453)
* Add view to support backend translation fetching

* Load backend translations from component json

* Translations for season sensor

* Scripts to merge and unpack Lokalise translations

* Fix copy paste error

* Serve post-lokalise translations to frontend

* Linting

* Auto-deploy translations with Travis

* Commit post-lokalise translation files

* Split logic into more helper functions

* Fall back to English for missing keys

* Move local translation copies to `.translations`

* Linting

* Initial tests

* Remove unnecessary file check

* Convert translation helper to async/await

* Convert translation helper tests to async/await

* Use set subtraction to find missing_components

* load_translation_files use component->file mapping

* Remove duplicated resources fetching

Get to take advantage of the slick Python 3.5 dict merging here.

* Switch to live project ID
2018-02-28 19:31:38 -08:00