mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-19 15:26:29 +00:00
Document as_int in NumberSelector
This commit is contained in:
parent
6295807b24
commit
e9bfd09545
40
blog/2024-11-08-number_selector.md
Normal file
40
blog/2024-11-08-number_selector.md
Normal file
@ -0,0 +1,40 @@
|
||||
---
|
||||
author: epenet
|
||||
authorURL: https://github.com/epenet
|
||||
title: "Return an integer in number selector"
|
||||
---
|
||||
|
||||
The [Number selector](https://www.home-assistant.io/docs/blueprint/selectors/#number-selector) has been expanded and now also includes an `as_int` parameter.
|
||||
|
||||
Using this in [config flows](/docs/data_entry_flow_index#show-form) will remove the need to add an extra validation to the schema.
|
||||
|
||||
Example:
|
||||
|
||||
```python
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_ADDRESS): NumberSelector(
|
||||
NumberSelectorConfig(
|
||||
as_int=True, min=1, max=255, mode=NumberSelectorMode.BOX
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
Old code:
|
||||
|
||||
```python
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_ADDRESS): vol.All(
|
||||
NumberSelector(
|
||||
NumberSelectorConfig(
|
||||
min=1, max=255, mode=NumberSelectorMode.BOX
|
||||
)
|
||||
),
|
||||
vol.Coerce(int),
|
||||
),
|
||||
}
|
||||
)
|
||||
```
|
Loading…
x
Reference in New Issue
Block a user