From 255f35b979aacaf9b3382d148e397ba38c1eb4fe Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Wed, 21 Dec 2022 10:43:49 +0100 Subject: [PATCH] Add support for translating custom attribute state (#83386) * Add support for translating custom attribute state * Address review comment * Rename attribute to state_attributes, allow naming attributes --- homeassistant/components/demo/climate.py | 5 ++- homeassistant/components/demo/strings.json | 32 ++++++++++++++++ .../components/demo/translations/en.json | 38 ++++++++++++++++++- homeassistant/components/demo/vacuum.py | 2 + script/hassfest/translations.py | 12 ++++-- 5 files changed, 83 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/demo/climate.py b/homeassistant/components/demo/climate.py index e41ca35fca2..7c0a4a5c9c8 100644 --- a/homeassistant/components/demo/climate.py +++ b/homeassistant/components/demo/climate.py @@ -104,6 +104,7 @@ class DemoClimate(ClimateEntity): """Representation of a demo climate device.""" _attr_should_poll = False + _attr_translation_key = "ubercool" def __init__( self, @@ -157,9 +158,9 @@ class DemoClimate(ClimateEntity): self._hvac_mode = hvac_mode self._aux = aux self._current_swing_mode = swing_mode - self._fan_modes = ["On Low", "On High", "Auto Low", "Auto High", "Off"] + self._fan_modes = ["on_low", "on_high", "auto_low", "auto_high", "off"] self._hvac_modes = hvac_modes - self._swing_modes = ["Auto", "1", "2", "3", "Off"] + self._swing_modes = ["auto", "1", "2", "3", "off"] self._target_temperature_high = target_temp_high self._target_temperature_low = target_temp_low diff --git a/homeassistant/components/demo/strings.json b/homeassistant/components/demo/strings.json index 2b90cf37d39..286bd5d0937 100644 --- a/homeassistant/components/demo/strings.json +++ b/homeassistant/components/demo/strings.json @@ -63,6 +63,29 @@ } }, "entity": { + "climate": { + "ubercool": { + "state_attributes": { + "fan_mode": { + "state": { + "auto_high": "Auto High", + "auto_low": "Auto Low", + "on_high": "On High", + "on_low": "On Low" + } + }, + "swing_mode": { + "state": { + "1": "1", + "2": "2", + "3": "3", + "auto": "Auto", + "off": "Off" + } + } + } + } + }, "select": { "speed": { "state": { @@ -81,6 +104,15 @@ "sleep": "Sleep" } } + }, + "vacuum": { + "model_s": { + "state_attributes": { + "cleaned_area": { + "name": "Cleaned Area" + } + } + } } } } diff --git a/homeassistant/components/demo/translations/en.json b/homeassistant/components/demo/translations/en.json index 8ad225d6966..a15834aa5a9 100644 --- a/homeassistant/components/demo/translations/en.json +++ b/homeassistant/components/demo/translations/en.json @@ -1,5 +1,28 @@ { "entity": { + "climate": { + "ubercool": { + "state_attributes": { + "fan_mode": { + "state": { + "auto_high": "Auto High", + "auto_low": "Auto Low", + "on_high": "On High", + "on_low": "On Low" + } + }, + "swing_mode": { + "state": { + "1": "1", + "2": "2", + "3": "3", + "auto": "Auto", + "off": "Off" + } + } + } + } + }, "select": { "speed": { "state": { @@ -18,6 +41,15 @@ "sleep": "Sleep" } } + }, + "vacuum": { + "model_s": { + "state_attributes": { + "cleaned_area": { + "name": "Cleaned Area" + } + } + } } }, "issues": { @@ -36,7 +68,8 @@ "fix_flow": { "abort": { "not_tea_time": "Can not re-heat the tea at this time" - } + }, + "step": {} }, "title": "The tea is cold" }, @@ -62,6 +95,9 @@ }, "options": { "step": { + "init": { + "data": {} + }, "options_1": { "data": { "bool": "Optional boolean", diff --git a/homeassistant/components/demo/vacuum.py b/homeassistant/components/demo/vacuum.py index c283ab5456f..11b69272775 100644 --- a/homeassistant/components/demo/vacuum.py +++ b/homeassistant/components/demo/vacuum.py @@ -105,6 +105,7 @@ class DemoVacuum(VacuumEntity): """Representation of a demo vacuum.""" _attr_should_poll = False + _attr_translation_key = "model_s" def __init__(self, name: str, supported_features: VacuumEntityFeature) -> None: """Initialize the vacuum.""" @@ -247,6 +248,7 @@ class StateDemoVacuum(StateVacuumEntity): _attr_should_poll = False _attr_supported_features = SUPPORT_STATE_SERVICES + _attr_translation_key = "model_s" def __init__(self, name: str) -> None: """Initialize the vacuum.""" diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 8fdf5e89715..a9612cf1943 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -269,9 +269,15 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema: }, vol.Optional("entity"): { str: { - str: vol.Schema( - {vol.Optional("state"): {str: cv.string_with_no_html}} - ) + str: { + vol.Optional("state_attributes"): { + str: { + vol.Optional("name"): cv.string_with_no_html, + vol.Optional("state"): {str: cv.string_with_no_html}, + } + }, + vol.Optional("state"): {str: cv.string_with_no_html}, + } } }, }