Added minimum/maximum to counter#17440
Conversation
This comment has been minimized.
This comment has been minimized.
| """Representation of a counter.""" | ||
|
|
||
| def __init__(self, object_id, name, initial, restore, step, icon): | ||
| def __init__(self, object_id, name, initial, min, max, restore, step, icon): |
There was a problem hiding this comment.
line too long (80 > 79 characters)
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
|
Could not find a related documentation PR. Added |
|
Doc modification would be trivial. Where do I have to add it? |
|
In the documentation repo, here's a direct link to the page in question: https://github.com/home-assistant/home-assistant.io/blob/next/source/_components/counter.markdown |
|
Thanks a lot tjorim! Sorry - I am quite new to this. |
|
At first glance it looks like that this PR wants to integrate functionality which the What's the use case for this? Edit: It's the |
|
No quite. This will make the counter never go over maximum or below minimum (if specified). |
|
The counter should count and not interpret values. Your issue can be solved with two conditions (or maybe even with one) in an automation rule. |
|
Yes, but then I have to check from every instance I send the increase/decrease commands instead of doing it in central place. Also with initial value, restore and step the counter already interprets values. |
You have to check it in every automation rule which is interacting with the counter, that's correct. The proposed solution would do it the other way around. Instead of using a condition, one would need to use multiple counters because they check if the value hits the threshold.
Those are the information to setup the counter.
Because if you know it then the condition is the right place. Automation rules can be changed during run time and their reloading is faster than reloading the core. |
I'm afraid I don't understand why I have to use multiple counters? Can you please elaborate?
Yes, the information is used to setup a counter, just like its min/max value would be. In my opinion it boils down to this:
Pros/Cons: Solution 1
Solution 2
Solution 2 is for me the way to go because every time I modify some config files I have to restart hass anyway. Also if one would like to change the boundaries dynamically one can still do this in automation. |
Because the counters would have different boundaries for different use cases. The use case for you is that you only want to have one counter "to rule them all".
The counter is an automation helper like the Threshold Binary Sensor or the Min/max Sensor. But this doesn't mean that those helpers or building blocks should cover every possible use case. Automation rules are well tested and the default way to handle state changes. Everything a helper can do, can be done in plain automation too. The comparison is more like this:
Solution 2
That may work for you but a lot of people don't want to restart or can't restart for every single configuration change.
Not possible, the counter is initialized with the boundaries and those can't be changed during run time.
In your case maybe but as we have the automation editor. There is not longer much need to edit the rules manually. If you do so then you are probably one that never going to use counter in the first place.
Again, may be true for your use case. In general only |
|
Can I propose that the boundaries can be changed through a service call ? |
|
Sure - both boundaries through one call ( set_boundaries ) or two separate calls ( set_minimum and set_maximum)? |
|
@fabaff : I think there is still some misunderstanding going on. I'll try again: Thanks to @dgomes idea, I've implemented a service call which can change the counter properties without having to restart. I've also create the unit-tests and the documentation. Imho this pretty much clears the cons-list in this PR. |
|
I think that the way the current boundaries are implemented, as configuration options on a per counter basis is good. This PR needs rebasing and I think that it's ok to merge. |
|
@spacemanspiff2007 I wanted to check in and see if you were going to have time to rebase this so it could be merged? I am willing to help with finishing it up if you don't have time. |
|
Oh, sorry - I did not realize I had something todo. |
|
To rebase, you'll need to pull down the latest changes from the dev branch and then replay your changes on top of them. You can start this process by running the following: This is going to take each of your commits one at a time and put them on top of the current dev branch. If there are conflicts (which there are some), it will pause and have you resolve them before continuing. Here's a good tutorial on rebasing: https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase |
|
I hope I've done it correct :-) |
|
@spacemanspiff2007 - looks like something nasty happened with the rebase and merge. There was a bunch of code from dev that appeared on your branch. I tried to clean it up but it did not work in this PR. I have a clean branch with your code on it, but don't have the permissions to push it up to your fork. A fixed branch is available here: https://github.com/home-assistant/home-assistant/compare/dev...rohankapoorcom:counter-min-max?expand=1 You are welcome to push that branch over to your fork and make a new pull request, or I can open a new one on your behalf. |
|
I have created a fresh repo and tried again: |
Description:
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: