-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Use explicit duration format for state formatting #23017
Conversation
That's a pretty good improvement. Over the years we used different formatting of duration (and we do have different classes) that all do the same. Aligning the duration (or for fields) in the automation picker is a thing on my wishlist. I actually even introduced a similar (if not same) function for the calendar trigger this month, https://github.com/home-assistant/frontend/blob/dev/src/common/datetime/format_duration.ts#L47, which could probably be removed as well with this, but I may open a PR myself after this one is merged. |
@silamon Yeah I focused the PR for state formatting but we should improve the other duration formats (It's now using a different function with the same name 🙈). I'll review your PR 👍 |
days, | ||
hours, |
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.
For the future I think we should use the precision to determine if we are also gonna add minutes and seconds, for now it is ok I think.
So, how do we set the precision on a duration class sensor from YAML? |
This change (together with #23132) appears to have broken sensible display of uptime sensors from ESPHome devices or any others that provide sensors of the duration device class measured in seconds. Being able to get uptime (or other durations) in a unit appropriate for its size is useful functionality: reading that something has occurred for "8,324 seconds" is simply not as user-friendly as seeing it as "2 hours, 18 minutes, and 44 seconds". The examples given in the description of the PR don't exhibit this counterintuitive behavior: they only exhibit numbers of hours less than 24 and minutes less than 60, but it's my understanding that a duration given as, say, "94.75 min" would be turned into "90m45 s", and not into "1h30m45s". I understand that this is the intended behavior of this PR, but not being able to override it and get back a behavior which uses units up to the largest one actually present in quantities greater than 1, instead of treating the given unit of measurement as the largest to be displayed, seems like a step backwards for readability of reported durations. |
If something is unclear or something is incorrect, please open a new issue. |
Proposed change
Improve duration format for state
Instead of using
hh:mm:ss
it will now use explicit format based on unit of measurement and precision.The rule of formatting is this one : We use the unit of measurement as main unit and we display the digits as secondary unit.
Examples :
0 h :
0h
0.5 h:
0h 30min
30 min:
30min
30.75 min:
30min 45s
fixes #21967
fixes #21984
fixes #18151
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: