-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Dont floor duration for milliseconds #23028
Conversation
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.
I had to do that because the duration format only support integer.
I'm just thinking, may be we should just drop duration formatting for millisecond and only relies on regular numeric state formatting.
Just remove ms
from this array and remove the ms
case.
export const DURATION_UNITS = ["ms", "s", "min", "h", "d"] as const;
WDYT @karwosts ?
Hmm I guess I don't really understand what you mean when you say "duration format". I tested this with some fractional ms and everything seemed to be working as expected. So I'm not sure what's not supported, (but I don't understand everything that's going on here). If you think dropping the ms section achieves the same effect, we could try that too. |
Using float for DurationFormat is not allowed. new Intl.DurationFormat("en").format({ milliseconds: 0.1 })
It works in your code because if it's fail, we catch the error and we fallback to regular state formatting but I would prefer to remove // state is duration
if (
attributes.device_class === "duration" &&
attributes.unit_of_measurement &&
DURATION_UNITS.includes(attributes.unit_of_measurement)
) {
try {
return formatDuration(
locale,
state,
attributes.unit_of_measurement,
entity?.display_precision
);
} catch (_err) {
// fallback to default
}
} |
Thank you for clarifying. Removing ms from DURATIONS seems to achieve the goal without any negative side effects as far as I can tell. I have made the change here. |
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.
Thank you 👌
* Dont floor duration for milliseconds * remove ms
Proposed change
Really like the new duration changes! However I was thinking maybe when a duration is set to milliseconds, we don't need to force round it.
If we don't floor, then the display is just controlled by display precision, so user can choose whole numbers or partial fraction.
If we floor, then there is no choice, and anything sub-1ms is always forced to
0 ms
.Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: