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)"), selector.SelectOptionDict(value="T", label="T (tera)"),
] ]
TIME_UNITS = [ TIME_UNITS = [
selector.SelectOptionDict(value=UnitOfTime.SECONDS, label="s (seconds)"), UnitOfTime.SECONDS,
selector.SelectOptionDict(value=UnitOfTime.MINUTES, label="min (minutes)"), UnitOfTime.MINUTES,
selector.SelectOptionDict(value=UnitOfTime.HOURS, label="h (hours)"), UnitOfTime.HOURS,
selector.SelectOptionDict(value=UnitOfTime.DAYS, label="d (days)"), UnitOfTime.DAYS,
] ]
INTEGRATION_METHODS = [ INTEGRATION_METHODS = [
selector.SelectOptionDict(value=METHOD_TRAPEZOIDAL, label="Trapezoidal rule"), METHOD_TRAPEZOIDAL,
selector.SelectOptionDict(value=METHOD_LEFT, label="Left Riemann sum"), METHOD_LEFT,
selector.SelectOptionDict(value=METHOD_RIGHT, label="Right Riemann sum"), METHOD_RIGHT,
] ]
OPTIONS_SCHEMA = vol.Schema( OPTIONS_SCHEMA = vol.Schema(
@ -61,7 +61,9 @@ CONFIG_SCHEMA = vol.Schema(
selector.EntitySelectorConfig(domain=SENSOR_DOMAIN) selector.EntitySelectorConfig(domain=SENSOR_DOMAIN)
), ),
vol.Required(CONF_METHOD, default=METHOD_TRAPEZOIDAL): selector.SelectSelector( 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( vol.Required(CONF_ROUND_DIGITS, default=2): selector.NumberSelector(
selector.NumberSelectorConfig( selector.NumberSelectorConfig(
@ -76,7 +78,9 @@ CONFIG_SCHEMA = vol.Schema(
), ),
vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector( vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector(
selector.SelectSelectorConfig( 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"
}
}
}
} }