core icon indicating copy to clipboard operation
core copied to clipboard

Use raw value for remaining time at Home Connect

Open Diegorro98 opened this issue 1 year ago • 6 comments

Breaking change

Proposed change

As discussed at https://github.com/home-assistant/core/pull/127870#discussion_r1790741729, API data should be displayed as raw as possible and sensor.remaining_program_time was performing a transformation to a timestamp (and the given name doesn't match the actual functionality).

These changes expose the raw value of the remaining program time and separates into a sensor class the old functionality that will be deprecated.

Also the name has been changed to match functionality.

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)
  • [X] Deprecation (breaking change to happen in the future)
  • [ ] Breaking change (fix/feature causing existing functionality to break)
  • [X] Code quality improvements to existing code or addition of tests

Additional information

If anyone wants to have this entity after its deprecation period, this is the template that you can use to achieve same functionality:

{% if (states("sensor.dishwasher_remaining_program_time") | is_number)
   and is_state("sensor.dishwasher_operation_state", "Run")
   or is_state("sensor.dishwasher_operation_state", "Pause")
   or is_state("sensor.dishwasher_operation_state", "Finished") %}
{{ now() + timedelta(seconds=states("sensor.dishwasher_remaining_program_time")|int) }}
{%- endif %}

Device class should be Timestamp and the template entity can be added to the device

Checklist

  • [X] The code change is tested and works locally.
  • [X] Local tests pass. Your PR cannot be merged unless tests pass
  • [X] There is no commented out code in this PR.
  • [X] I have followed the development checklist
  • [X] I have followed the perfect PR recommendations
  • [X] The code has been formatted using Ruff (ruff format homeassistant tests)
  • [X] 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:

Diegorro98 avatar Oct 09 '24 10:10 Diegorro98

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

Code owner commands

Code owners of home_connect 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 home_connect 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.

home-assistant[bot] avatar Oct 09 '24 10:10 home-assistant[bot]

I commented on the other comment. But in generally we dont want time counting date,.since that created history every time increment. This make me think this is a bad idea.

elupus avatar Oct 10 '24 04:10 elupus

The update frequency will be the same, as it doesn't change how it is updated, so it will not be updated every second. The only modification made here is the removal of timestamp calculations in the base sensor entity, which have been relocated to another class for deprecation and future removal, and expose the value given from the API.

The only thing that might be updated every second is the template sensor that you can create with the template I've posted for people that wants to keep this timestamp after the removal of the entity.

Diegorro98 avatar Oct 10 '24 14:10 Diegorro98

If its a duration to when something is to happen. The timestamp value will end up being mostly constant. If the value written to state is the same as before, this does not lead to a state update that is pushed to all web clients.

elupus avatar Oct 10 '24 14:10 elupus

"mostly constant" image EDIT: well, in fact is pretty constant for 4 hours of program

Diegorro98 avatar Oct 10 '24 14:10 Diegorro98

"mostly constant" image EDIT: well, in fact is pretty constant for 4 hours of program

We usually prefer if timestamps are checked, and avoid state update if the error is withing some given tolerance (say a few % of total duration).

elupus avatar Oct 10 '24 15:10 elupus