From b15d3132b0d70f143fc0799fb5dd4d56f822fc02 Mon Sep 17 00:00:00 2001 From: abmantis Date: Wed, 13 Nov 2024 16:49:18 +0000 Subject: [PATCH 1/8] Add native_unit_of_measurement to translation tests --- tests/helpers/test_translation.py | 38 +++++++++++++++++-- .../test/translations/de.json | 5 ++- .../test/translations/en.json | 7 +++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 3b60c7f695bc60..3fdc564bf93539 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -64,10 +64,16 @@ def test_load_translations_files_by_language( "test": { "entity": { "switch": { - "other1": {"name": "Other 1"}, + "other1": { + "name": "Other 1", + "native_unit_of_measurement": "Units", + }, "other2": {"name": "Other 2"}, "other3": {"name": "Other 3"}, - "other4": {"name": "Other 4"}, + "other4": { + "name": "Other 4", + "native_unit_of_measurement": "Quantities", + }, "outlet": {"name": "Outlet " "{placeholder}"}, } }, @@ -87,9 +93,11 @@ def test_load_translations_files_by_language( "en", { "component.test.entity.switch.other1.name": "Other 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", }, [], @@ -98,9 +106,11 @@ def test_load_translations_files_by_language( "es", { "component.test.entity.switch.other1.name": "Otra 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", }, [], @@ -110,12 +120,14 @@ def test_load_translations_files_by_language( { # Correct "component.test.entity.switch.other1.name": "Anderes 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Einheiten", # Translation has placeholder missing in English "component.test.entity.switch.other2.name": "Other 2", # Correct (empty translation) "component.test.entity.switch.other3.name": "", # Translation missing "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", # Mismatch in placeholders "component.test.entity.switch.outlet.name": "Outlet {placeholder}", }, @@ -166,9 +178,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Other 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -176,24 +190,33 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: hass, "de", "entity", {"test"} ) + # Test a partial translation assert translations == { + # Correct "component.test.entity.switch.other1.name": "Anderes 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Einheiten", + # Translation has placeholder missing in English "component.test.entity.switch.other2.name": "Other 2", + # Correct (empty translation) "component.test.entity.switch.other3.name": "", + # Translation missing "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + # Mismatch in placeholders "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } - # Test a partial translation translations = await translation.async_get_translations( hass, "es", "entity", {"test"} ) assert translations == { "component.test.entity.switch.other1.name": "Otra 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", } @@ -204,9 +227,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Other 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -507,9 +532,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - ) assert translations == { "component.test.entity.switch.other1.name": "Other 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -522,9 +549,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - assert translations == { "component.test.entity.switch.other1.name": "Otra 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", } @@ -539,9 +568,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - assert translations == { "component.test.entity.switch.other1.name": "Other 1", + "component.test.entity.switch.other1.native_unit_of_measurement": "Units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", + "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -678,7 +709,6 @@ async def test_get_translations_still_has_title_without_translations_files( ) assert translations == translations_again - assert translations == { "component.component1.title": "Component 1", } diff --git a/tests/testing_config/custom_components/test/translations/de.json b/tests/testing_config/custom_components/test/translations/de.json index 57d26f28ec0327..4d8ffa46c92696 100644 --- a/tests/testing_config/custom_components/test/translations/de.json +++ b/tests/testing_config/custom_components/test/translations/de.json @@ -1,7 +1,10 @@ { "entity": { "switch": { - "other1": { "name": "Anderes 1" }, + "other1": { + "name": "Anderes 1", + "native_unit_of_measurement": "Einheiten" + }, "other2": { "name": "Anderes 2 {placeholder}" }, "other3": { "name": "" }, "outlet": { "name": "Steckdose {something}" } diff --git a/tests/testing_config/custom_components/test/translations/en.json b/tests/testing_config/custom_components/test/translations/en.json index 7ed32c224a71bd..d54a1f5466e2d7 100644 --- a/tests/testing_config/custom_components/test/translations/en.json +++ b/tests/testing_config/custom_components/test/translations/en.json @@ -1,10 +1,13 @@ { "entity": { "switch": { - "other1": { "name": "Other 1" }, + "other1": { "name": "Other 1", "native_unit_of_measurement": "Units" }, "other2": { "name": "Other 2" }, "other3": { "name": "Other 3" }, - "other4": { "name": "Other 4" }, + "other4": { + "name": "Other 4", + "native_unit_of_measurement": "Quantities" + }, "outlet": { "name": "Outlet {placeholder}" } } }, From c6c35e3654b98dcc53d8bd0fb726026e26f261a9 Mon Sep 17 00:00:00 2001 From: abmantis Date: Thu, 14 Nov 2024 11:13:48 +0000 Subject: [PATCH 2/8] Add unit translations for youtube, fitbit and withings --- homeassistant/components/fitbit/sensor.py | 6 ++++-- homeassistant/components/fitbit/strings.json | 8 ++++++++ homeassistant/components/withings/strings.json | 6 ++++-- homeassistant/components/youtube/strings.json | 10 ++++++++-- script/hassfest/translations.py | 3 +++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/fitbit/sensor.py b/homeassistant/components/fitbit/sensor.py index ab9a593e195915..f37144fc535439 100644 --- a/homeassistant/components/fitbit/sensor.py +++ b/homeassistant/components/fitbit/sensor.py @@ -265,11 +265,12 @@ class FitbitSensorEntityDescription(SensorEntityDescription): ), FitbitSensorEntityDescription( key="activities/steps", - name="Steps", + translation_key="steps", native_unit_of_measurement="steps", icon="mdi:walk", scope=FitbitScope.ACTIVITY, state_class=SensorStateClass.TOTAL_INCREASING, + has_entity_name=True, ), FitbitSensorEntityDescription( key="activities/tracker/activityCalories", @@ -370,13 +371,14 @@ class FitbitSensorEntityDescription(SensorEntityDescription): ), FitbitSensorEntityDescription( key="activities/tracker/steps", - name="Tracker Steps", + translation_key="steps", native_unit_of_measurement="steps", icon="mdi:walk", scope=FitbitScope.ACTIVITY, entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, entity_category=EntityCategory.DIAGNOSTIC, + has_entity_name=True, ), FitbitSensorEntityDescription( key="body/bmi", diff --git a/homeassistant/components/fitbit/strings.json b/homeassistant/components/fitbit/strings.json index e1ca1b01f7a681..b08ac8087ecd24 100644 --- a/homeassistant/components/fitbit/strings.json +++ b/homeassistant/components/fitbit/strings.json @@ -38,6 +38,14 @@ }, "battery_level": { "name": "Battery level" + }, + "steps": { + "name": "Steps", + "native_unit_of_measurement": "steps" + }, + "tracker_steps": { + "name": "Tracker Steps", + "native_unit_of_measurement": "steps" } } }, diff --git a/homeassistant/components/withings/strings.json b/homeassistant/components/withings/strings.json index 775ef5cdaab3ee..a22be14bbe90d2 100644 --- a/homeassistant/components/withings/strings.json +++ b/homeassistant/components/withings/strings.json @@ -203,7 +203,8 @@ "name": "Wakeup time" }, "step_goal": { - "name": "Step goal" + "name": "Step goal", + "native_unit_of_measurement": "steps" }, "sleep_goal": { "name": "Sleep goal" @@ -212,7 +213,8 @@ "name": "Weight goal" }, "activity_steps_today": { - "name": "Steps today" + "name": "Steps today", + "native_unit_of_measurement": "steps" }, "activity_distance_today": { "name": "Distance travelled today" diff --git a/homeassistant/components/youtube/strings.json b/homeassistant/components/youtube/strings.json index 78ca0532459df0..67d878eca2a402 100644 --- a/homeassistant/components/youtube/strings.json +++ b/homeassistant/components/youtube/strings.json @@ -47,8 +47,14 @@ "published_at": { "name": "Published at" } } }, - "subscribers": { "name": "Subscribers" }, - "views": { "name": "Views" } + "subscribers": { + "name": "Subscribers", + "native_unit_of_measurement": "subscribers" + }, + "views": { + "name": "Views", + "native_unit_of_measurement": "views" + } } } } diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 2c3b9b4d99b981..9efd308ee268d4 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -368,6 +368,9 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema: }, slug_validator=translation_key_validator, ), + vol.Optional( + "native_unit_of_measurement" + ): translation_value_validator, }, slug_validator=translation_key_validator, ), From 79ee3ffef57727b1981b4a99967d09152e59dd64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ab=C3=ADlio=20Costa?= Date: Thu, 14 Nov 2024 11:25:50 +0000 Subject: [PATCH 3/8] Apply suggestions from code review Co-authored-by: Joost Lekkerkerker --- homeassistant/components/fitbit/sensor.py | 2 +- homeassistant/components/fitbit/strings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/fitbit/sensor.py b/homeassistant/components/fitbit/sensor.py index f37144fc535439..df8bf440cb75b3 100644 --- a/homeassistant/components/fitbit/sensor.py +++ b/homeassistant/components/fitbit/sensor.py @@ -371,7 +371,7 @@ class FitbitSensorEntityDescription(SensorEntityDescription): ), FitbitSensorEntityDescription( key="activities/tracker/steps", - translation_key="steps", + translation_key="tracker_steps", native_unit_of_measurement="steps", icon="mdi:walk", scope=FitbitScope.ACTIVITY, diff --git a/homeassistant/components/fitbit/strings.json b/homeassistant/components/fitbit/strings.json index b08ac8087ecd24..9647c89a09cc44 100644 --- a/homeassistant/components/fitbit/strings.json +++ b/homeassistant/components/fitbit/strings.json @@ -44,7 +44,7 @@ "native_unit_of_measurement": "steps" }, "tracker_steps": { - "name": "Tracker Steps", + "name": "Tracker steps", "native_unit_of_measurement": "steps" } } From 91ab5ffda1063779fdb650ca05730e18038a51a2 Mon Sep 17 00:00:00 2001 From: abmantis Date: Thu, 14 Nov 2024 12:02:30 +0000 Subject: [PATCH 4/8] Revert fitbit changes --- homeassistant/components/fitbit/sensor.py | 6 ++---- homeassistant/components/fitbit/strings.json | 8 -------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/fitbit/sensor.py b/homeassistant/components/fitbit/sensor.py index df8bf440cb75b3..ab9a593e195915 100644 --- a/homeassistant/components/fitbit/sensor.py +++ b/homeassistant/components/fitbit/sensor.py @@ -265,12 +265,11 @@ class FitbitSensorEntityDescription(SensorEntityDescription): ), FitbitSensorEntityDescription( key="activities/steps", - translation_key="steps", + name="Steps", native_unit_of_measurement="steps", icon="mdi:walk", scope=FitbitScope.ACTIVITY, state_class=SensorStateClass.TOTAL_INCREASING, - has_entity_name=True, ), FitbitSensorEntityDescription( key="activities/tracker/activityCalories", @@ -371,14 +370,13 @@ class FitbitSensorEntityDescription(SensorEntityDescription): ), FitbitSensorEntityDescription( key="activities/tracker/steps", - translation_key="tracker_steps", + name="Tracker Steps", native_unit_of_measurement="steps", icon="mdi:walk", scope=FitbitScope.ACTIVITY, entity_registry_enabled_default=False, state_class=SensorStateClass.TOTAL_INCREASING, entity_category=EntityCategory.DIAGNOSTIC, - has_entity_name=True, ), FitbitSensorEntityDescription( key="body/bmi", diff --git a/homeassistant/components/fitbit/strings.json b/homeassistant/components/fitbit/strings.json index 9647c89a09cc44..e1ca1b01f7a681 100644 --- a/homeassistant/components/fitbit/strings.json +++ b/homeassistant/components/fitbit/strings.json @@ -38,14 +38,6 @@ }, "battery_level": { "name": "Battery level" - }, - "steps": { - "name": "Steps", - "native_unit_of_measurement": "steps" - }, - "tracker_steps": { - "name": "Tracker steps", - "native_unit_of_measurement": "steps" } } }, From 7f8d0e8c982b8568da818b61ffebcaf3996dae0c Mon Sep 17 00:00:00 2001 From: abmantis Date: Thu, 14 Nov 2024 16:42:30 +0000 Subject: [PATCH 5/8] Drop withings changes --- homeassistant/components/withings/strings.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/withings/strings.json b/homeassistant/components/withings/strings.json index a22be14bbe90d2..775ef5cdaab3ee 100644 --- a/homeassistant/components/withings/strings.json +++ b/homeassistant/components/withings/strings.json @@ -203,8 +203,7 @@ "name": "Wakeup time" }, "step_goal": { - "name": "Step goal", - "native_unit_of_measurement": "steps" + "name": "Step goal" }, "sleep_goal": { "name": "Sleep goal" @@ -213,8 +212,7 @@ "name": "Weight goal" }, "activity_steps_today": { - "name": "Steps today", - "native_unit_of_measurement": "steps" + "name": "Steps today" }, "activity_distance_today": { "name": "Distance travelled today" From 693e3fa0f5e590b0048a8bafcfd8dfcd663116d7 Mon Sep 17 00:00:00 2001 From: abmantis Date: Mon, 18 Nov 2024 18:44:23 +0000 Subject: [PATCH 6/8] Translate github and revert youtube --- homeassistant/components/github/sensor.py | 6 ------ homeassistant/components/github/strings.json | 18 ++++++++++++------ homeassistant/components/youtube/strings.json | 10 ++-------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/github/sensor.py b/homeassistant/components/github/sensor.py index 9a2b5ef5ac4fff..614ebe254c4819 100644 --- a/homeassistant/components/github/sensor.py +++ b/homeassistant/components/github/sensor.py @@ -37,7 +37,6 @@ class GitHubSensorEntityDescription(SensorEntityDescription): GitHubSensorEntityDescription( key="discussions_count", translation_key="discussions_count", - native_unit_of_measurement="Discussions", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data["discussion"]["total"], @@ -45,7 +44,6 @@ class GitHubSensorEntityDescription(SensorEntityDescription): GitHubSensorEntityDescription( key="stargazers_count", translation_key="stargazers_count", - native_unit_of_measurement="Stars", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data["stargazers_count"], @@ -53,7 +51,6 @@ class GitHubSensorEntityDescription(SensorEntityDescription): GitHubSensorEntityDescription( key="subscribers_count", translation_key="subscribers_count", - native_unit_of_measurement="Watchers", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data["watchers"]["total"], @@ -61,7 +58,6 @@ class GitHubSensorEntityDescription(SensorEntityDescription): GitHubSensorEntityDescription( key="forks_count", translation_key="forks_count", - native_unit_of_measurement="Forks", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data["forks_count"], @@ -69,7 +65,6 @@ class GitHubSensorEntityDescription(SensorEntityDescription): GitHubSensorEntityDescription( key="issues_count", translation_key="issues_count", - native_unit_of_measurement="Issues", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data["issue"]["total"], @@ -77,7 +72,6 @@ class GitHubSensorEntityDescription(SensorEntityDescription): GitHubSensorEntityDescription( key="pulls_count", translation_key="pulls_count", - native_unit_of_measurement="Pull Requests", entity_category=EntityCategory.DIAGNOSTIC, state_class=SensorStateClass.MEASUREMENT, value_fn=lambda data: data["pull_request"]["total"], diff --git a/homeassistant/components/github/strings.json b/homeassistant/components/github/strings.json index 38b796e2fd22b0..4d0acb5c801610 100644 --- a/homeassistant/components/github/strings.json +++ b/homeassistant/components/github/strings.json @@ -19,22 +19,28 @@ "entity": { "sensor": { "discussions_count": { - "name": "Discussions" + "name": "Discussions", + "native_unit_of_measurement": "discussions" }, "stargazers_count": { - "name": "Stars" + "name": "Stars", + "native_unit_of_measurement": "stars" }, "subscribers_count": { - "name": "Watchers" + "name": "Watchers", + "native_unit_of_measurement": "watchers" }, "forks_count": { - "name": "Forks" + "name": "Forks", + "native_unit_of_measurement": "forks" }, "issues_count": { - "name": "Issues" + "name": "Issues", + "native_unit_of_measurement": "issues" }, "pulls_count": { - "name": "Pull requests" + "name": "Pull requests", + "native_unit_of_measurement": "pull requests" }, "latest_commit": { "name": "Latest commit" diff --git a/homeassistant/components/youtube/strings.json b/homeassistant/components/youtube/strings.json index 67d878eca2a402..78ca0532459df0 100644 --- a/homeassistant/components/youtube/strings.json +++ b/homeassistant/components/youtube/strings.json @@ -47,14 +47,8 @@ "published_at": { "name": "Published at" } } }, - "subscribers": { - "name": "Subscribers", - "native_unit_of_measurement": "subscribers" - }, - "views": { - "name": "Views", - "native_unit_of_measurement": "views" - } + "subscribers": { "name": "Subscribers" }, + "views": { "name": "Views" } } } } From 6161ab6266d06df1e0aa55b0cdbb72f16611ecbe Mon Sep 17 00:00:00 2001 From: abmantis Date: Mon, 18 Nov 2024 18:49:35 +0000 Subject: [PATCH 7/8] Change test translations to non-capitalised --- tests/helpers/test_translation.py | 44 +++++++++---------- .../test/translations/de.json | 2 +- .../test/translations/en.json | 4 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index 3fdc564bf93539..bfb4047d3955f2 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -66,13 +66,13 @@ def test_load_translations_files_by_language( "switch": { "other1": { "name": "Other 1", - "native_unit_of_measurement": "Units", + "native_unit_of_measurement": "units", }, "other2": {"name": "Other 2"}, "other3": {"name": "Other 3"}, "other4": { "name": "Other 4", - "native_unit_of_measurement": "Quantities", + "native_unit_of_measurement": "quantities", }, "outlet": {"name": "Outlet " "{placeholder}"}, } @@ -93,11 +93,11 @@ def test_load_translations_files_by_language( "en", { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", }, [], @@ -106,11 +106,11 @@ def test_load_translations_files_by_language( "es", { "component.test.entity.switch.other1.name": "Otra 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", }, [], @@ -120,14 +120,14 @@ def test_load_translations_files_by_language( { # Correct "component.test.entity.switch.other1.name": "Anderes 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Einheiten", + "component.test.entity.switch.other1.native_unit_of_measurement": "einheiten", # Translation has placeholder missing in English "component.test.entity.switch.other2.name": "Other 2", # Correct (empty translation) "component.test.entity.switch.other3.name": "", # Translation missing "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", # Mismatch in placeholders "component.test.entity.switch.outlet.name": "Outlet {placeholder}", }, @@ -178,11 +178,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -194,14 +194,14 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { # Correct "component.test.entity.switch.other1.name": "Anderes 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Einheiten", + "component.test.entity.switch.other1.native_unit_of_measurement": "einheiten", # Translation has placeholder missing in English "component.test.entity.switch.other2.name": "Other 2", # Correct (empty translation) "component.test.entity.switch.other3.name": "", # Translation missing "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", # Mismatch in placeholders "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -212,11 +212,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Otra 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", } @@ -227,11 +227,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -532,11 +532,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - ) assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -549,11 +549,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - assert translations == { "component.test.entity.switch.other1.name": "Otra 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", } @@ -568,11 +568,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "Units", + "component.test.entity.switch.other1.native_unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "Quantities", + "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } diff --git a/tests/testing_config/custom_components/test/translations/de.json b/tests/testing_config/custom_components/test/translations/de.json index 4d8ffa46c92696..5239db51521517 100644 --- a/tests/testing_config/custom_components/test/translations/de.json +++ b/tests/testing_config/custom_components/test/translations/de.json @@ -3,7 +3,7 @@ "switch": { "other1": { "name": "Anderes 1", - "native_unit_of_measurement": "Einheiten" + "native_unit_of_measurement": "einheiten" }, "other2": { "name": "Anderes 2 {placeholder}" }, "other3": { "name": "" }, diff --git a/tests/testing_config/custom_components/test/translations/en.json b/tests/testing_config/custom_components/test/translations/en.json index d54a1f5466e2d7..24ce2cf0d505c3 100644 --- a/tests/testing_config/custom_components/test/translations/en.json +++ b/tests/testing_config/custom_components/test/translations/en.json @@ -1,12 +1,12 @@ { "entity": { "switch": { - "other1": { "name": "Other 1", "native_unit_of_measurement": "Units" }, + "other1": { "name": "Other 1", "native_unit_of_measurement": "units" }, "other2": { "name": "Other 2" }, "other3": { "name": "Other 3" }, "other4": { "name": "Other 4", - "native_unit_of_measurement": "Quantities" + "native_unit_of_measurement": "quantities" }, "outlet": { "name": "Outlet {placeholder}" } } From 1e3f629765b8dcd1ba4829e4d2a9e04caa91f58c Mon Sep 17 00:00:00 2001 From: abmantis Date: Wed, 20 Nov 2024 12:13:32 +0000 Subject: [PATCH 8/8] Rename translation key to unit_of_measurement --- homeassistant/components/github/strings.json | 12 ++--- script/hassfest/translations.py | 2 +- tests/helpers/test_translation.py | 44 +++++++++---------- .../test/translations/de.json | 2 +- .../test/translations/en.json | 4 +- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/homeassistant/components/github/strings.json b/homeassistant/components/github/strings.json index 4d0acb5c801610..bcda47d72fb79f 100644 --- a/homeassistant/components/github/strings.json +++ b/homeassistant/components/github/strings.json @@ -20,27 +20,27 @@ "sensor": { "discussions_count": { "name": "Discussions", - "native_unit_of_measurement": "discussions" + "unit_of_measurement": "discussions" }, "stargazers_count": { "name": "Stars", - "native_unit_of_measurement": "stars" + "unit_of_measurement": "stars" }, "subscribers_count": { "name": "Watchers", - "native_unit_of_measurement": "watchers" + "unit_of_measurement": "watchers" }, "forks_count": { "name": "Forks", - "native_unit_of_measurement": "forks" + "unit_of_measurement": "forks" }, "issues_count": { "name": "Issues", - "native_unit_of_measurement": "issues" + "unit_of_measurement": "issues" }, "pulls_count": { "name": "Pull requests", - "native_unit_of_measurement": "pull requests" + "unit_of_measurement": "pull requests" }, "latest_commit": { "name": "Latest commit" diff --git a/script/hassfest/translations.py b/script/hassfest/translations.py index 9efd308ee268d4..2965ccb7406014 100644 --- a/script/hassfest/translations.py +++ b/script/hassfest/translations.py @@ -369,7 +369,7 @@ def gen_strings_schema(config: Config, integration: Integration) -> vol.Schema: slug_validator=translation_key_validator, ), vol.Optional( - "native_unit_of_measurement" + "unit_of_measurement" ): translation_value_validator, }, slug_validator=translation_key_validator, diff --git a/tests/helpers/test_translation.py b/tests/helpers/test_translation.py index bfb4047d3955f2..d4a78807e2b20c 100644 --- a/tests/helpers/test_translation.py +++ b/tests/helpers/test_translation.py @@ -66,13 +66,13 @@ def test_load_translations_files_by_language( "switch": { "other1": { "name": "Other 1", - "native_unit_of_measurement": "units", + "unit_of_measurement": "units", }, "other2": {"name": "Other 2"}, "other3": {"name": "Other 3"}, "other4": { "name": "Other 4", - "native_unit_of_measurement": "quantities", + "unit_of_measurement": "quantities", }, "outlet": {"name": "Outlet " "{placeholder}"}, } @@ -93,11 +93,11 @@ def test_load_translations_files_by_language( "en", { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", }, [], @@ -106,11 +106,11 @@ def test_load_translations_files_by_language( "es", { "component.test.entity.switch.other1.name": "Otra 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", }, [], @@ -120,14 +120,14 @@ def test_load_translations_files_by_language( { # Correct "component.test.entity.switch.other1.name": "Anderes 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "einheiten", + "component.test.entity.switch.other1.unit_of_measurement": "einheiten", # Translation has placeholder missing in English "component.test.entity.switch.other2.name": "Other 2", # Correct (empty translation) "component.test.entity.switch.other3.name": "", # Translation missing "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", # Mismatch in placeholders "component.test.entity.switch.outlet.name": "Outlet {placeholder}", }, @@ -178,11 +178,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -194,14 +194,14 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { # Correct "component.test.entity.switch.other1.name": "Anderes 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "einheiten", + "component.test.entity.switch.other1.unit_of_measurement": "einheiten", # Translation has placeholder missing in English "component.test.entity.switch.other2.name": "Other 2", # Correct (empty translation) "component.test.entity.switch.other3.name": "", # Translation missing "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", # Mismatch in placeholders "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -212,11 +212,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Otra 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", } @@ -227,11 +227,11 @@ async def test_get_translations(hass: HomeAssistant, mock_config_flows) -> None: assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -532,11 +532,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - ) assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } @@ -549,11 +549,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - assert translations == { "component.test.entity.switch.other1.name": "Otra 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Otra 2", "component.test.entity.switch.other3.name": "Otra 3", "component.test.entity.switch.other4.name": "Otra 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Enchufe {placeholder}", } @@ -568,11 +568,11 @@ async def test_get_cached_translations(hass: HomeAssistant, mock_config_flows) - assert translations == { "component.test.entity.switch.other1.name": "Other 1", - "component.test.entity.switch.other1.native_unit_of_measurement": "units", + "component.test.entity.switch.other1.unit_of_measurement": "units", "component.test.entity.switch.other2.name": "Other 2", "component.test.entity.switch.other3.name": "Other 3", "component.test.entity.switch.other4.name": "Other 4", - "component.test.entity.switch.other4.native_unit_of_measurement": "quantities", + "component.test.entity.switch.other4.unit_of_measurement": "quantities", "component.test.entity.switch.outlet.name": "Outlet {placeholder}", } diff --git a/tests/testing_config/custom_components/test/translations/de.json b/tests/testing_config/custom_components/test/translations/de.json index 5239db51521517..8cac140c753328 100644 --- a/tests/testing_config/custom_components/test/translations/de.json +++ b/tests/testing_config/custom_components/test/translations/de.json @@ -3,7 +3,7 @@ "switch": { "other1": { "name": "Anderes 1", - "native_unit_of_measurement": "einheiten" + "unit_of_measurement": "einheiten" }, "other2": { "name": "Anderes 2 {placeholder}" }, "other3": { "name": "" }, diff --git a/tests/testing_config/custom_components/test/translations/en.json b/tests/testing_config/custom_components/test/translations/en.json index 24ce2cf0d505c3..802c859e922cd1 100644 --- a/tests/testing_config/custom_components/test/translations/en.json +++ b/tests/testing_config/custom_components/test/translations/en.json @@ -1,12 +1,12 @@ { "entity": { "switch": { - "other1": { "name": "Other 1", "native_unit_of_measurement": "units" }, + "other1": { "name": "Other 1", "unit_of_measurement": "units" }, "other2": { "name": "Other 2" }, "other3": { "name": "Other 3" }, "other4": { "name": "Other 4", - "native_unit_of_measurement": "quantities" + "unit_of_measurement": "quantities" }, "outlet": { "name": "Outlet {placeholder}" } }