From 9fda1b71a8292936498dba4a69cbf16880a7b4e8 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:51:53 +0100 Subject: [PATCH] Update 2024-11-08-number_selector.md --- blog/2024-11-08-number_selector.md | 33 +++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/blog/2024-11-08-number_selector.md b/blog/2024-11-08-number_selector.md index b921578b..b503aa0c 100644 --- a/blog/2024-11-08-number_selector.md +++ b/blog/2024-11-08-number_selector.md @@ -4,18 +4,19 @@ authorURL: https://github.com/epenet title: "Number selector adds integer return value support" --- -The [Number selector](https://www.home-assistant.io/docs/blueprint/selectors/#number-selector) now includes an `as_int` parameter. +### Summary of changes +Passing an integer step to a [Number selector](https://www.home-assistant.io/docs/blueprint/selectors/#number-selector) will now validate the user input as an integer. Set this parameter in [config flows](/docs/data_entry_flow_index#show-form) to eliminate the extra schema validation step. -New implementation (using `as_int` parameter): +New implementation (using an integer step): ```python vol.Schema( { vol.Optional(CONF_ADDRESS): NumberSelector( NumberSelectorConfig( - as_int=True, min=1, max=255, mode=NumberSelectorMode.BOX + min=1, max=255, mode=NumberSelectorMode.BOX, step=1 ) ), } @@ -38,3 +39,29 @@ vol.Schema( } ) ``` + +### Backwards compatibility + +To improve backwards compatibility, the default value has been adjust from `step=1` to `step=1.0`. + +However, integrations that set the step explicitly to an integer value may need to adjust the step to the corresponding float to allow float values. + +New implementation (using an float step) to ensure a float is accepted: + +```python +NumberSelector( + NumberSelectorConfig( + min=0, max=100, mode=NumberSelectorMode.BOX, step=5.0 + ) +) +``` + +Previous implementation: + +```python +NumberSelector( + NumberSelectorConfig( + min=0, max=100, mode=NumberSelectorMode.BOX, step=5 + ) +) +```