Skip to content

Allow fetching translations by categories#34329

Merged
balloob merged 7 commits intodevfrom
translation-categories
Apr 19, 2020
Merged

Allow fetching translations by categories#34329
balloob merged 7 commits intodevfrom
translation-categories

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented Apr 17, 2020

Breaking change

Proposed change

This allows fetching translations by categories instead of fetching everything at once. This also allows specifying if you want to load a single integration, all set up integrations or all set up integrations + all integrations that have config flows.

Marked WIP until I finish frontend PR.

Frontend PR home-assistant/frontend#5560

Part of #34264

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

@probot-home-assistant
Copy link
Copy Markdown

Hey there @home-assistant/core, mind taking a look at this pull request as its been labeled with a integration (onboarding) you are listed as a codeowner for? Thanks!

@probot-home-assistant
Copy link
Copy Markdown

Hey there @home-assistant/frontend, mind taking a look at this pull request as its been labeled with a integration (frontend) you are listed as a codeowner for? Thanks!

@balloob balloob marked this pull request as ready for review April 17, 2020 18:17
@balloob
Copy link
Copy Markdown
Member Author

balloob commented Apr 17, 2020

One final bug left when setting up a new integration during onboarding…

Fixed

2020-04-17 13:22:18 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.4709422416] Error handling message: Unknown error
Traceback (most recent call last):
  File "/Users/paulus/dev/hass/home-assistant/homeassistant/components/websocket_api/decorators.py", line 20, in _handle_async_response
    await func(hass, connection, msg)
  File "/Users/paulus/dev/hass/home-assistant/homeassistant/components/frontend/__init__.py", line 558, in websocket_get_translations
    msg.get("config_flow"),
  File "/Users/paulus/dev/hass/home-assistant/homeassistant/helpers/translation.py", line 198, in async_get_translations
    results = await asyncio.gather(*tasks)
  File "/Users/paulus/dev/hass/home-assistant/homeassistant/helpers/translation.py", line 167, in async_get_component_resources
    return build_resources(translation_cache, components)
  File "/Users/paulus/dev/hass/home-assistant/homeassistant/helpers/translation.py", line 101, in build_resources
    resources[domain].update(translation_cache[component])
KeyError: 'media_player.cast'

@balloob
Copy link
Copy Markdown
Member Author

balloob commented Apr 18, 2020

@Mariusthvdb this should fix your Hue hiccuping when you open the frontend.

@Mariusthvdb
Copy link
Copy Markdown
Contributor

Mariusthvdb commented Apr 18, 2020

@Mariusthvdb this should fix your Hue hiccuping when you open the frontend.

great! and thanks ;-)

happy to report that since upgrading from 107.x to 108.4 the HA instance has never been so fast, responsive and, important, without 'unavailable' (#knockonwood) Hue entities. I've re-instated all core Hue sensors, and they seem very reliable, where before, they would go just as of the 'unavailable' as the lights.

Please keep on knocking these details, HA keeps getting better and better.
Thanks for the tag and the heads-on. Appreciated.

translation_cache: Dict[str, Dict[str, Any]], components: Iterable[str]
translation_cache: Dict[str, Dict[str, Any]],
components: Set[str],
category: Optional[str],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the other categories than the languages?

resources[domain].update(translation_cache[component])

if category is None:
domain_resources.update(translation_cache[component])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the translation cache contain keys that are either languages or domains?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

categories are the top level entries in strings.json. config, options, etc. A list is here

So the dict is

{ "light": { "device_automation": {…} }

cache: Dict[str, Dict[str, Any]] = hass.data.setdefault(
TRANSLATION_STRING_CACHE, {}
)
translation_cache: Dict[str, Any] = cache.setdefault(language, {})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we seem to set a language as top level key in the translation cache. How does that match with your description in the comment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I got confused with all the nested dicts. The translation cache here and what we return is one level below the language key.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We return translation_cache, which has the described structure.

You're right that cache is { language: translation_cache }.

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@balloob balloob merged commit 98f1548 into dev Apr 19, 2020
@balloob balloob deleted the translation-categories branch April 19, 2020 00:13
@lock lock Bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants