-
-
Notifications
You must be signed in to change notification settings - Fork 29.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a locale to the alexa remote capability #121636
base: dev
Are you sure you want to change the base?
Add a locale to the alexa remote capability #121636
Conversation
…g locale. This local is read from the users config.
Hey there @home-assistant/cloud, @ochlocracy, @jbouwh, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
def add_mode(self, value: str, labels: list[str]) -> None: | ||
"""Add mode to the supportedModes object.""" | ||
self.add_mode_with_locale(value, {label: "" for label in labels}) | ||
|
||
def add_mode_with_locale(self, value: str, labels: dict[str, str]) -> None: | ||
"""Add mode to the supportedModes object.""" | ||
self._supported_modes.append({"value": value, "labels": labels}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do we implement 2 methods here as we do not seem to use the empty label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry i think i don't fully understand you.
So we have 2 methods here, one to add just a label and one to add the label with a locale. Because the _supported_modes attribute does only accept a label with a locale a placeholder is set as locale.
Later when the _supported_modes field is added to the capabilities object the placeholder is replaced by the default locale en-US. See line 244 in resources.py.
I did this because then there is only one place that uses the default locale. If you think that is confusing i can just replace the placeholder with the default locale.
def add_preset(self, value: float, labels: list[str]) -> None: | ||
"""Add preset to configuration presets array.""" | ||
self.add_preset_with_locale(value, {label: "" for label in labels}) | ||
|
||
def add_preset_with_locale(self, value: float, labels: dict[str, str]) -> None: | ||
"""Add preset to configuration presets array.""" | ||
self._presets.append({"value": value, "labels": labels}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beside of some tests that fail. Be aware that predefined labels in Home Assistant are English. An integration can add backend translations to the states. I am not sure if we should set the locale to the labels as it should be the job of the integration to do the translations IMO.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
I don't think they are related to my PR, do you? At least it does not look like they are. Everything is fine after merging the latest changes. |
I think the problem are not the predefined labels but the generic ones. Especially the remote can have any name for an activity. Those activity names are most probably not english but in the language of the user. That's why i added the users locale to the label. |
The language of the user is not always the locale in Alexa, As e.g. Dutch is not supported. |
Sure. Tests work fine now after a merge with dev. |
Hm okay, but wouldn't it still make more sense to set the Alexa locale as the labels locale instead of the default english one? |
Well as integrations also should try to localise and we are aiming to use English in the base, it seems obvious the activity could have translations in the integration. So that is why I think we should not go this path |
Okay i see what you mean. Maybe instead of assuming which local should be used we could let the user configure it. Something like that:
And if this configuration is not available we could just use the english locale with the activity name (just like its done right now). |
I see what you mean, but IMO we should not create special functionality for locales in this case. I'll add a tag to ask for a second opinion. |
May I ask you why not? The benefit from using the right locale with a label is that Alexa is performing way better. |
https://github.com/home-assistant/architecture/blob/master/adr/0007-integration-config-yaml-structure.md: We should not increase disparity. https://github.com/home-assistant/architecture/blob/master/adr/0009-translations-2.0.md: Remove support for integrations providing platform translations (that includes https://github.com/home-assistant/architecture/blob/master/adr/0021-YAML-integration-configuration-deprecation-policy.md: Any additions to the YAML schema means we need to maintain the code, and when it changes, allow a deprecation period. Finally: |
Proposed change
This PR adds the feature to use the locale from the alexa configuration when creating non default capability labels.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: