feat: add next rate structure (and time) property #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have the next rate structures for my TOU plan hardcoded into a Home Assistant template in a pretty ugly way. I want to be able to easily know the next rate structure (and when it will happen) so I can automatically perform operations like preconditioning the AC.
This PR performs a optimized calculation to determine when the next rate structure will be. A naive approach to this probably would loop through ever hour of every day for the next year. However, since rates can only change between hours and between weekdays / weekends, this can be heavily optimized to only check ~2 days per month.
The basic concept is, looping through each month:
Python is not a language I really ever use so please let me know if I am breaking some unknown Python style or best practices 😄
Also, it would be nice to return both the structure int and time in the same call, but
ha-openeiexpects any tuples returned to have the second value be the unit of measure. Let me know if you want to adjust this!