developers.home-assistant/blog/2024-11-08-number_selector.md

1.5 KiB

author authorURL title
epenet https://github.com/epenet Number selector adds integer return value support

Summary of changes

Passing an integer step to a Number selector will now validate the user input as an integer.

Set this parameter in config flows to eliminate the extra schema validation step.

New implementation (using an integer step):

vol.Optional(CONF_ADDRESS): NumberSelector(
    NumberSelectorConfig(
        min=1, max=255, mode=NumberSelectorMode.BOX, step=1
    )
)

Previous implementation (with explicit integer conversion):

vol.Optional(CONF_ADDRESS): vol.All(
    NumberSelector(
        NumberSelectorConfig(
            min=1, max=255, mode=NumberSelectorMode.BOX
        )
    ),
    vol.Coerce(int),
)

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:

NumberSelector(
    NumberSelectorConfig(
        min=0, max=100, mode=NumberSelectorMode.BOX, step=5.0
    )
)

Previous implementation:

NumberSelector(
    NumberSelectorConfig(
        min=0, max=100, mode=NumberSelectorMode.BOX, step=5
    )
)