-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to force number selector as an integer #130104
base: dev
Are you sure you want to change the base?
Conversation
Hey there @yuxincs, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Hey there @autinerd, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Hey there @autinerd, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Hey there @MartinHjelmare, @functionpointer, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
homeassistant/helpers/selector.py
Outdated
"any", vol.All(vol.Coerce(float), vol.Range(min=1e-3)) | ||
# if step is an integer, a validation of integer will be enforced | ||
vol.Optional("step", default=1.0): vol.Any( | ||
"any", int, vol.All(vol.Coerce(float), vol.Range(min=1e-3)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need vol.Range(min=1))
also for int so it's not set to 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
Added...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MySensors part looks good
69cb431
to
98b4924
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
There are more integrations that are converting to int but I guess these ones are the most obvious ones.
I don't really see the problem with composing validators. That's a fundamental feature and idea of our validation system. |
This is too implicit in my opinion:
|
I think this should be further discussed before we add it if at all. |
There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days. |
Breaking change
Integrations using an explicit step with an integer value will now have the value validated.
If this behavior is not desired, please adjust the step to a float (
1
=>1.0
)Proposed change
As I was reviewing #130084, I realised that there was no easy way to force a
NumberSelector
to return an integer, and developers had to rely onvol.All(NumberSelector(...), vol.Coerce(int))
The default behavior for
NumberSelector
has been updated, such that setting the step as an integer will now cause validation of the value, to ensure it is an integerTo improve backwards compatibility, the default step value has been adjusted from 1 (integer) to 1.0 (float)
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: