-
-
Notifications
You must be signed in to change notification settings - Fork 95
Extend custom sensor operators #894
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
base: main
Are you sure you want to change the base?
Conversation
I added support for single operand operations and many others that I could even remotely think they could be useful. Single operands are used by omitting the registers, as that would be the second operand. Yes, you can do all of this stuff with HA's template sensors, but this is much cleaner.
Refined the list a bit and added comments.
Guldoman
left a comment
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.
It looks like there were a bunch of reverts, were they done by accident?
Like the self._requests = profile["requests"] and the value = (value - maxint) ones.
|
Mhh, yeah. I didn't mean those. I only meant to change the _read_registers_custom function. The main branch of my fork doesn't have those, but the branch I pushed does, for some reason, and I didn't realize. Anyway, anything outside _read_registers_custom is unintended. |
Fixed unintended reverts and some mistakes with unhandled divisions by 0.
|
Now it should be fixed. About the names. I don't know if you are ok with alternative names, so feel free to drop them or change them if you have better ideas. As long as the operations are there, the names are less important. |
Refactor _read_registers_custom to handle variables and improve logic for register checks.
|
Just added support for variables. To declare a variable use "define: {var_name}" p.s. after a define, "value" is reset to 0 |
Refactor operator handling and variable management in sensor processing.
|
I've made some minor tweaks, and even so I still don't like the validation part, I think it's now mergeable. Just check if it still works for you. 😉 |
741d5f4 to
36abfef
Compare
Refined operator list and added plain numbers support for variables.
|
Yeah, seems to work fine. I put some more thought into the operator list, especially the names, as I realized that once they go live they cannot be easily taken back. Should at least be decent now. I didn't touch the validation part, but what don't you like about it? Lastly, this is an example sensor I made with this: |
I added support for single operand operators and many others that I could even remotely think they could be useful.
This might be overkill, but I don't think there's any harm in having them. And yes, you can do all of this stuff with HA's template sensors, but this is a much cleaner alternative.
Single operands are used by omitting the registers, as that would be the second operand. Adding a way to have 3 or more operands would expand the possibilities even more, even if just constants defined in the definition file.
Right now there's no documentation for this feature aside for some examples where only "subtract" is used. But if this (or part of it) is merged, documenting it is in order.