Skip to content

Removed rounding of durations in Here Travel Time sensors #146838

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

Merged

Conversation

etiennec78
Copy link
Contributor

Proposed change

Previously, time sensor values were rounded off, reducing their accuracy.
Having untouched float values allows automation to have the arrival value to the second, and the history graph to be more precise.
Finally, this doesn't cause any inconvenience, as the UI only displays one digit after the decimal point, and for automations there's the states(entity_id, rounded=True) template.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @eifinger, mind taking a look at this pull request as it has been labeled with an integration (here_travel_time) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of here_travel_time can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign here_travel_time Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@etiennec78 etiennec78 marked this pull request as draft June 15, 2025 17:08
@eifinger
Copy link
Contributor

Looks good from my POV

@etiennec78 etiennec78 marked this pull request as ready for review June 16, 2025 09:05
Comment on lines 170 to 172
duration=duration / 60,
duration_in_traffic=duration_in_traffic / 60,
distance=distance,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is this used? I think we can remove the / 60 as well. Sensors have a native unit of measurement, which is the unit the entity returns the state in, and a suggested unit of measurement. So if we get the value in hours, we can set the native unit of measurement in hours and set the suggested unit of measurement to minutes and that would save a bit of extra calculation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is used in the duration and duration_in_traffic sensors:

SensorEntityDescription(
translation_key="duration",
icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DURATION,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
SensorEntityDescription(
translation_key="duration_in_traffic",
icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DURATION_IN_TRAFFIC,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTime.MINUTES,
),

They are currently configured with minutes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but what is the source unit then?

We should add a device class for these 2 (I think I saw a PR of that fly by last weekend)

Copy link
Contributor

@eifinger eifinger Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the rounding the source unit is seconds.
The PR for the device_class is: #146804

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, then we can just set the native_unit_of_measurement to seconds and set a suggested_unit_of_measurement to minutes and then we don't have any conversion logic in the integration anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I opened PR #146804 to add the device class, if you need maybe we can merge it first.
And about the native unit of measurement, I was also thinking of making it seconds, however it makes HA show "783 s" instead of "13min 3s".
It seems that this behavior is linked to the duration value being reported as a float by the library, even though the decimal part is always 0.
Either we could change the duration type returned by the library, or we could add an int conversion for duration sensors in this integration.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Home Assistant will do that conversion for you with suggested_unit_of_measurement :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, the conversion is in the integration itself, I'll send a commit to fix that

@home-assistant home-assistant bot marked this pull request as draft June 16, 2025 12:14
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@etiennec78 etiennec78 marked this pull request as ready for review June 16, 2025 13:03
@home-assistant home-assistant bot requested a review from joostlek June 16, 2025 13:03
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase

@home-assistant home-assistant bot marked this pull request as draft June 16, 2025 13:16
etiennec78 and others added 3 commits June 16, 2025 15:20
@etiennec78 etiennec78 marked this pull request as ready for review June 16, 2025 13:22
@home-assistant home-assistant bot requested a review from joostlek June 16, 2025 13:22
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing

@home-assistant home-assistant bot marked this pull request as draft June 16, 2025 13:29
@etiennec78 etiennec78 marked this pull request as ready for review June 16, 2025 14:24
@home-assistant home-assistant bot requested a review from joostlek June 16, 2025 14:24
@etiennec78
Copy link
Contributor Author

Sorry for all these requests, everything should be good now 👍

@joostlek joostlek merged commit ad3dac0 into home-assistant:dev Jun 16, 2025
34 checks passed
@etiennec78 etiennec78 deleted the here_travel_time_float_distance branch June 16, 2025 20:59
@github-actions github-actions bot locked and limited conversation to collaborators Jun 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants