Add support for field descriptions in config flows (#68604)

This commit is contained in:
Paulus Schoutsen 2022-03-24 17:25:50 -07:00 committed by GitHub
parent 63ca0e70be
commit 20c0a5a838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 6 deletions

View File

@ -3,7 +3,6 @@
"step": {
"user": {
"title": "New Derivative sensor",
"description": "Precision controls the number of decimal digits in the output.\nIf the time window is not 0, the sensor's value is a time weighted moving average of derivatives within the window.\nThe derivative will be scaled according to the selected metric prefix and time unit of the derivative.",
"data": {
"name": "Name",
"round": "Precision",
@ -11,6 +10,11 @@
"time_window": "Time window",
"unit_prefix": "Metric prefix",
"unit_time": "Time unit"
},
"data_description": {
"round": "Controls the number of decimal digits in the output.",
"time_window": "If set, the sensor's value is a time weighted moving average of derivatives within this window.",
"unit_prefix": "The derivative will be scaled according to the selected metric prefix and time unit of the derivative."
}
}
}
@ -18,7 +22,6 @@
"options": {
"step": {
"options": {
"description": "[%key:component::derivative::config::step::user::description%]",
"data": {
"name": "[%key:component::derivative::config::step::user::data::name%]",
"round": "[%key:component::derivative::config::step::user::data::round%]",
@ -26,6 +29,11 @@
"time_window": "[%key:component::derivative::config::step::user::data::time_window%]",
"unit_prefix": "[%key:component::derivative::config::step::user::data::unit_prefix%]",
"unit_time": "[%key:component::derivative::config::step::user::data::unit_time%]"
},
"data_description": {
"round": "[%key:component::derivative::config::step::user::data_description::round%]",
"time_window": "[%key:component::derivative::config::step::user::data_description::time_window%]",
"unit_prefix": "[%key:component::derivative::config::step::user::data_description::unit_prefix%]."
}
}
}

View File

@ -10,7 +10,11 @@
"unit_prefix": "Metric prefix",
"unit_time": "Time unit"
},
"description": "Precision controls the number of decimal digits in the output.\nIf the time window is not 0, the sensor's value is a time weighted moving average of derivatives within the window.\nThe derivative will be scaled according to the selected metric prefix and time unit of the derivative.",
"data_description": {
"round": "Controls the number of decimal digits in the output.",
"time_window": "If set, the sensor's value is a time weighted moving average of derivatives within this window.",
"unit_prefix": "The derivative will be scaled according to the selected metric prefix and time unit of the derivative."
},
"title": "New Derivative sensor"
}
}
@ -26,7 +30,11 @@
"unit_prefix": "Metric prefix",
"unit_time": "Time unit"
},
"description": "Precision controls the number of decimal digits in the output.\nIf the time window is not 0, the sensor's value is a time weighted moving average of derivatives within the window.\nThe derivative will be scaled according to the selected metric prefix and time unit of the derivative."
"data_description": {
"round": "Controls the number of decimal digits in the output.",
"time_window": "If set, the sensor's value is a time weighted moving average of derivatives within this window.",
"unit_prefix": "The derivative will be scaled according to the selected metric prefix and time unit of the derivative.."
}
}
}
}

View File

@ -110,6 +110,7 @@ def gen_data_entry_schema(
step_title_class("title"): cv.string_with_no_html,
vol.Optional("description"): cv.string_with_no_html,
vol.Optional("data"): {str: cv.string_with_no_html},
vol.Optional("data_description"): {str: cv.string_with_no_html},
vol.Optional("menu_options"): {str: cv.string_with_no_html},
}
},
@ -125,7 +126,19 @@ def gen_data_entry_schema(
removed_title_validator, config, integration
)
return schema
def data_description_validator(value):
"""Validate data description."""
for step_info in value["step"].values():
if "data_description" not in step_info:
continue
for key in step_info["data_description"]:
if key not in step_info["data"]:
raise vol.Invalid(f"data_description key {key} is not in data")
return value
return vol.All(vol.Schema(schema), data_description_validator)
def gen_strings_schema(config: Config, integration: Integration):