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 wrap around support in counter component #132575

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

CrazyVito11
Copy link

@CrazyVito11 CrazyVito11 commented Dec 7, 2024

Proposed change

This PR implements my own feature request I made on the community form a couple of months ago.

It adds an option to allow the counter component to wrap around once it reached it's minimum or maximum value.
The idea here is that it allows you to make it easier to wrap through lists, like for example a button that lists through scenes.

Right now I already have an automation that does this scene switching, but I have to manually reset the counter once I reach the end. This PR should automate that.

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:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

Hi @CrazyVito11

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

home-assistant bot commented Dec 7, 2024

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

Code owner commands

Code owners of counter 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 counter 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.

Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

We discussed this in the core meeting, and we found that the use case to go through scenes would technically also be possible using a select or input_select and the select.next service (maybe has a different name, haven't checked).

So would it be possible to add some use cases for other scenarios where you could use this?

@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft January 16, 2025 14:31
@CrazyVito11
Copy link
Author

You could potentially also use this for reminding yourself to do maintenance after X amount of cycles, without having to set the counter to the maximum value again manually in the automation.

Example case 1
You want to periodically check the oil level of your car, but you don't have the ability to read the amount of kilometers driven in Home Assistant.
You could calculate the average trip length you make and then calculate how many trips you would have to make before reaching the desired distance between oil checks.
This value could then be set at the maximum value of the counter, which counts down by one every time the car is used.
An example trigger could be a sensor that goes offline (out of reach) or if CarPlay/Android Auto is activated by your phone.

Example case 2
You want to clean a washing machine after a certain amount of washing cycles to make sure the machine is clean and prevent buildup that could cause damage to the machine.
A vibration sensor or power plug could be used to sense when the machine is active, and then count down each time it was activated.

The upside of the counter being able to wrap around automatically, is that if you ever want to change the amount of cycles, you only have to update the counter's max value, and not also the set_value inside the automation.
Making it a bit less error prone.

@CrazyVito11 CrazyVito11 marked this pull request as ready for review January 18, 2025 10:23
@home-assistant home-assistant bot requested a review from joostlek January 18, 2025 10:23
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.

3 participants