timer-bar-card
timer-bar-card copied to clipboard
Add "remaining" attribute
For LG Sensors, an initial time and remaining time attribute is provided. Therefore, for correct timing, adding an attribute "remaining" that can specify where to read the exact remaining time makes sense.
This is the final result.
I was hoping I'd never have to support a remaining attribute. It's yet another complication to the card's configuration.
However, I took a look through the LG ThinQ integration to see how easy it would be to add support for a start time or end time value. LG designed their API so all that you get back is time remaining and initial duration, so calculating an accurate and consistent start time would be impossible, especially because they don't even give you seconds remaining!
So I'm willing to merge this.
I'll take a deeper look into the PR and what more documentation this needs later. However, I just enabled CI and want to mention some things:
-
Ignore HACS Action. I don't know what it's complaining about but I'll probably turn it off for pull requests.
-
This PR as it stands breaks the card with native Home Assistant timers. These native timers are smart in that they don't update their values every second to avoid flooding the system with data. The frontend instead compensates for the lack of updates by adjusting the remaining time with how much time has passed until the sensor changed value. If the time remaining is 5 seconds but was updated 3 seconds ago, the time remaining shown on the frontend is 2 seconds.
This code path is no longer executed due to line 55, but I'd be curious if the LG integration behaves correctly if you used the new
remainingAttr
function in line 57. Since I'd assume the LG integration updates close to every minute, I imagine there wouldn't be much difference in behavior.
Did a small refactor and also renamed the attribute internally to make it different from the usage of "remaining" that was already there. Seems like both timers are now working as I would expect:
I'm going to merge this in and make a few more changes. Thank you so much for the pull request!