From 017a5848224788a31ae1482b6604f15d0675c9b8 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Sun, 26 Oct 2025 19:19:17 +0000 Subject: [PATCH] Feedback --- .../components/compensation/__init__.py | 6 +- .../components/compensation/config_flow.py | 59 ++++++++++++------- .../components/compensation/const.py | 1 + .../components/compensation/strings.json | 36 ++++++++--- 4 files changed, 72 insertions(+), 30 deletions(-) diff --git a/homeassistant/components/compensation/__init__.py b/homeassistant/components/compensation/__init__.py index 82d2ffc473a1..7ab042ab5b30 100644 --- a/homeassistant/components/compensation/__init__.py +++ b/homeassistant/components/compensation/__init__.py @@ -35,6 +35,7 @@ from .const import ( CONF_DEGREE, CONF_LOWER_LIMIT, CONF_POLYNOMIAL, + CONF_POLYNOMIAL_CONFIG, CONF_PRECISION, CONF_UPPER_LIMIT, DATA_COMPENSATION, @@ -168,11 +169,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Compensation from a config entry.""" config = dict(entry.options) - data_points: list[dict[str, float]] = config[CONF_DATAPOINTS] + data_points: list[dict[str, float]] = config[CONF_POLYNOMIAL_CONFIG][ + CONF_DATAPOINTS + ] new_data_points = [ [data_point["compensated_value"], data_point["uncompensated_value"]] for data_point in data_points ] + config[CONF_DEGREE] = config[CONF_POLYNOMIAL_CONFIG][CONF_DEGREE] config[CONF_DATAPOINTS] = new_data_points await create_compensation_data(hass, entry.entry_id, config, True) diff --git a/homeassistant/components/compensation/config_flow.py b/homeassistant/components/compensation/config_flow.py index f494eb93a5cc..c1980670374e 100644 --- a/homeassistant/components/compensation/config_flow.py +++ b/homeassistant/components/compensation/config_flow.py @@ -13,6 +13,7 @@ from homeassistant.const import ( CONF_NAME, CONF_UNIT_OF_MEASUREMENT, ) +from homeassistant.data_entry_flow import SectionConfig, section from homeassistant.helpers.schema_config_entry_flow import ( SchemaCommonFlowHandler, SchemaConfigFlowHandler, @@ -37,6 +38,7 @@ from .const import ( CONF_DATAPOINTS, CONF_DEGREE, CONF_LOWER_LIMIT, + CONF_POLYNOMIAL_CONFIG, CONF_PRECISION, CONF_UPPER_LIMIT, DEFAULT_DEGREE, @@ -52,27 +54,45 @@ async def get_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema: return vol.Schema( { - vol.Required(CONF_DATAPOINTS): ObjectSelector( - ObjectSelectorConfig( - label_field="uncompensated_value", - description_field="compensated_value", - multiple=True, - translation_key=CONF_DATAPOINTS, - fields={ - "uncompensated_value": ObjectSelectorField( - required=True, - selector=NumberSelector( - NumberSelectorConfig(mode=NumberSelectorMode.BOX) - ), + vol.Required(CONF_POLYNOMIAL_CONFIG): section( + vol.Schema( + { + vol.Required(CONF_DATAPOINTS): ObjectSelector( + ObjectSelectorConfig( + label_field="uncompensated_value", + description_field="compensated_value", + multiple=True, + translation_key=CONF_DATAPOINTS, + fields={ + "uncompensated_value": ObjectSelectorField( + required=True, + selector=NumberSelector( + NumberSelectorConfig( + mode=NumberSelectorMode.BOX + ) + ), + ), + "compensated_value": ObjectSelectorField( + required=True, + selector=NumberSelector( + NumberSelectorConfig( + mode=NumberSelectorMode.BOX + ) + ), + ), + }, + ) ), - "compensated_value": ObjectSelectorField( - required=True, - selector=NumberSelector( - NumberSelectorConfig(mode=NumberSelectorMode.BOX) - ), + vol.Optional( + CONF_DEGREE, default=DEFAULT_DEGREE + ): NumberSelector( + NumberSelectorConfig( + min=0, max=7, step=1, mode=NumberSelectorMode.BOX + ) ), }, - ) + ), + SectionConfig(collapsed=False), ), vol.Optional(CONF_ATTRIBUTE): AttributeSelector( AttributeSelectorConfig(entity_id=entity_id) @@ -82,9 +102,6 @@ async def get_options_schema(handler: SchemaCommonFlowHandler) -> vol.Schema: vol.Optional(CONF_PRECISION, default=DEFAULT_PRECISION): NumberSelector( NumberSelectorConfig(min=0, step=1, mode=NumberSelectorMode.BOX) ), - vol.Optional(CONF_DEGREE, default=DEFAULT_DEGREE): NumberSelector( - NumberSelectorConfig(min=0, max=7, step=1, mode=NumberSelectorMode.BOX) - ), vol.Optional(CONF_UNIT_OF_MEASUREMENT): TextSelector(), } ) diff --git a/homeassistant/components/compensation/const.py b/homeassistant/components/compensation/const.py index 13b9740afa5f..6b8f0c7f1d0a 100644 --- a/homeassistant/components/compensation/const.py +++ b/homeassistant/components/compensation/const.py @@ -14,6 +14,7 @@ CONF_DATAPOINTS = "data_points" CONF_DEGREE = "degree" CONF_PRECISION = "precision" CONF_POLYNOMIAL = "polynomial" +CONF_POLYNOMIAL_CONFIG = "polynomial_config" DATA_COMPENSATION = "compensation_data" diff --git a/homeassistant/components/compensation/strings.json b/homeassistant/components/compensation/strings.json index fe40b5e80102..ca9e43055889 100644 --- a/homeassistant/components/compensation/strings.json +++ b/homeassistant/components/compensation/strings.json @@ -21,22 +21,32 @@ "options": { "description": "Refer to the documentation for further details on how to configure the compensation sensor using these options.", "data": { - "data_points": "Data points", "attribute": "Attribute", "upper_limit": "Upper limit", "lower_limit": "Lower limit", "precision": "Precision", - "degree": "Degree", + "unit_of_measurement": "Unit of measurement" }, "data_description": { - "data_points": "Add a collection of data point conversions with the uncompensated value and the compensated value. The number of required data point sets is equal to the polynomial degree + 1.", "attribute": "Attribute from the source to monitor/compensate.", "upper_limit": "Enables a upper limit for the sensor. The upper limit is defined by the data points highest uncompensated value.", "lower_limit": "Enables a lower limit for the sensor. The lower limit is defined by the data points lowest uncompensated value.", "precision": "Defines the precision of the calculated values, through the argument of round().", - "degree": "The degree of the polynomial.", "unit_of_measurement": "The unit of measurement of the compensation sensor, if any." + }, + "sections": { + "polynomial_config": { + "name": "Polynomial configuration", + "description": "Configure the polynomial used for compensation.", + "data": { + "data_points": "Data points", + "degree": "Degree" + }, + "data_description": { + "degree": "The degree of the polynomial." + } + } } } } @@ -52,22 +62,32 @@ "init": { "description": "[%key:component::compensation::config::step::options::description%]", "data": { - "data_points": "[%key:component::compensation::config::step::options::data::data_points%]", "attribute": "[%key:component::compensation::config::step::options::data::attribute%]", "upper_limit": "[%key:component::compensation::config::step::options::data::upper_limit%]", "lower_limit": "[%key:component::compensation::config::step::options::data::lower_limit%]", "precision": "[%key:component::compensation::config::step::options::data::precision%]", - "degree": "[%key:component::compensation::config::step::options::data::degree%]", "unit_of_measurement": "[%key:component::compensation::config::step::options::data::unit_of_measurement%]" }, "data_description": { - "data_points": "[%key:component::compensation::config::step::options::data_description::data_points%]", "attribute": "[%key:component::compensation::config::step::options::data_description::attribute%]", "upper_limit": "[%key:component::compensation::config::step::options::data_description::upper_limit%]", "lower_limit": "[%key:component::compensation::config::step::options::data_description::lower_limit%]", "precision": "[%key:component::compensation::config::step::options::data_description::precision%]", - "degree": "[%key:component::compensation::config::step::options::data_description::degree%]", "unit_of_measurement": "[%key:component::compensation::config::step::options::data_description::unit_of_measurement%]" + }, + + "sections": { + "polynomial_config": { + "name": "[%key:component::compensation::config::step::options::sections::polynomial_config::name%]", + "description": "[%key:component::compensation::config::step::options::sections::polynomial_config::description%]", + "data": { + "data_points": "[%key:component::compensation::config::step::options::sections::polynomial_config::data::data_points%]", + "degree": "[%key:component::compensation::config::step::options::sections::polynomial_config::data::degree%]" + }, + "data_description": { + "degree": "[%key:component::compensation::config::step::options::sections::polynomial_config::data_description::degree%]" + } + } } } }