From 1b1f8a1d6182e8a074ac039fef535113dc7dbcc0 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Tue, 24 Jan 2023 13:22:33 +0100 Subject: [PATCH] Add translation support for select selectors of integration `integration` config flow (#86212) * Translation support method * Translation support time unit * Remove redundant labels --- .../components/integration/config_flow.py | 22 +++++++++++-------- .../components/integration/strings.json | 17 ++++++++++++++ .../integration/translations/en.json | 19 +++++++++++++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/integration/config_flow.py b/homeassistant/components/integration/config_flow.py index 147c4262319..65840383926 100644 --- a/homeassistant/components/integration/config_flow.py +++ b/homeassistant/components/integration/config_flow.py @@ -33,15 +33,15 @@ UNIT_PREFIXES = [ selector.SelectOptionDict(value="T", label="T (tera)"), ] TIME_UNITS = [ - selector.SelectOptionDict(value=UnitOfTime.SECONDS, label="s (seconds)"), - selector.SelectOptionDict(value=UnitOfTime.MINUTES, label="min (minutes)"), - selector.SelectOptionDict(value=UnitOfTime.HOURS, label="h (hours)"), - selector.SelectOptionDict(value=UnitOfTime.DAYS, label="d (days)"), + UnitOfTime.SECONDS, + UnitOfTime.MINUTES, + UnitOfTime.HOURS, + UnitOfTime.DAYS, ] INTEGRATION_METHODS = [ - selector.SelectOptionDict(value=METHOD_TRAPEZOIDAL, label="Trapezoidal rule"), - selector.SelectOptionDict(value=METHOD_LEFT, label="Left Riemann sum"), - selector.SelectOptionDict(value=METHOD_RIGHT, label="Right Riemann sum"), + METHOD_TRAPEZOIDAL, + METHOD_LEFT, + METHOD_RIGHT, ] OPTIONS_SCHEMA = vol.Schema( @@ -61,7 +61,9 @@ CONFIG_SCHEMA = vol.Schema( selector.EntitySelectorConfig(domain=SENSOR_DOMAIN) ), vol.Required(CONF_METHOD, default=METHOD_TRAPEZOIDAL): selector.SelectSelector( - selector.SelectSelectorConfig(options=INTEGRATION_METHODS), + selector.SelectSelectorConfig( + options=INTEGRATION_METHODS, translation_key=CONF_METHOD + ), ), vol.Required(CONF_ROUND_DIGITS, default=2): selector.NumberSelector( selector.NumberSelectorConfig( @@ -76,7 +78,9 @@ CONFIG_SCHEMA = vol.Schema( ), vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector( selector.SelectSelectorConfig( - options=TIME_UNITS, mode=selector.SelectSelectorMode.DROPDOWN + options=TIME_UNITS, + mode=selector.SelectSelectorMode.DROPDOWN, + translation_key=CONF_UNIT_TIME, ), ), } diff --git a/homeassistant/components/integration/strings.json b/homeassistant/components/integration/strings.json index 4eb3b952a78..3a3940ffc2c 100644 --- a/homeassistant/components/integration/strings.json +++ b/homeassistant/components/integration/strings.json @@ -32,5 +32,22 @@ } } } + }, + "selector": { + "method": { + "options": { + "trapezoidal": "Trapezoidal rule", + "left": "Left Riemann sum", + "right": "Right Riemann sum" + } + }, + "unit_time": { + "options": { + "s": "Seconds", + "min": "Minutes", + "h": "Hours", + "d": "Days" + } + } } } diff --git a/homeassistant/components/integration/translations/en.json b/homeassistant/components/integration/translations/en.json index 1ee047b447f..e4ad2abde01 100644 --- a/homeassistant/components/integration/translations/en.json +++ b/homeassistant/components/integration/translations/en.json @@ -32,5 +32,22 @@ } } }, - "title": "Integration - Riemann sum integral sensor" + "title": "Integration - Riemann sum integral sensor", + "selector": { + "method": { + "options": { + "trapezoidal": "Trapezoidal rule", + "left": "Left Riemann sum", + "right": "Right Riemann sum" + } + }, + "unit_time": { + "options": { + "s": "Seconds", + "min": "Minutes", + "h": "Hours", + "d": "Days" + } + } + } } \ No newline at end of file