Skip to content
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

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Nov 8, 2024

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 on vol.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 integer

To improve backwards compatibility, the default step value has been adjusted from 1 (integer) to 1.0 (float)

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Nov 8, 2024

Hey there @yuxincs, mind taking a look at this pull request as it has been labeled with an integration (apcupsd) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of apcupsd can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign apcupsd Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

home-assistant bot commented Nov 8, 2024

Hey there @autinerd, mind taking a look at this pull request as it has been labeled with an integration (enigma2) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of enigma2 can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign enigma2 Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

home-assistant bot commented Nov 8, 2024

Hey there @autinerd, mind taking a look at this pull request as it has been labeled with an integration (webmin) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of webmin can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign webmin Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@home-assistant
Copy link

home-assistant bot commented Nov 8, 2024

Hey there @MartinHjelmare, @functionpointer, mind taking a look at this pull request as it has been labeled with an integration (mysensors) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of mysensors can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign mysensors Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@epenet epenet marked this pull request as ready for review November 12, 2024 08:56
@home-assistant home-assistant bot requested a review from frenck November 12, 2024 08:56
"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))
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍
Added...

Copy link
Contributor

@functionpointer functionpointer left a 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

Copy link
Member

@gjohansson-ST gjohansson-ST left a 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.

@frenck frenck added this to the 2024.12.0b0 milestone Nov 25, 2024
@MartinHjelmare
Copy link
Member

I don't really see the problem with composing validators. That's a fundamental feature and idea of our validation system.

@MartinHjelmare
Copy link
Member

This is too implicit in my opinion:

setting the step as an integer will now cause validation of the value, to ensure it is an integer

@MartinHjelmare MartinHjelmare marked this pull request as draft November 27, 2024 11:08
@MartinHjelmare MartinHjelmare added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Nov 27, 2024
@MartinHjelmare
Copy link
Member

I think this should be further discussed before we add it if at all.

@MartinHjelmare MartinHjelmare removed this from the 2024.12.0b0 milestone Nov 27, 2024
Copy link

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.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.