1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Add translation support for select selectors of integration integration config flow (#86212)

* Translation support method

* Translation support time unit

* Remove redundant labels
This commit is contained in:
Jan Bouwhuis 2023-01-24 13:22:33 +01:00 committed by GitHub
parent 1b4fda2321
commit 1b1f8a1d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 10 deletions

View File

@ -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,
),
),
}

View File

@ -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"
}
}
}
}

View File

@ -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"
}
}
}
}