Skip to content

Add duration sensor to Home Connect#167976

Draft
Diegorro98 wants to merge 4 commits intohome-assistant:devfrom
Diegorro98:home_connect/add_program_duration_sensor
Draft

Add duration sensor to Home Connect#167976
Diegorro98 wants to merge 4 commits intohome-assistant:devfrom
Diegorro98:home_connect/add_program_duration_sensor

Conversation

@Diegorro98
Copy link
Copy Markdown
Contributor

Proposed change

We currently support showing to the user at what time does it finish the program, but when the user hasn't selected yet a program, there isn't any information about how long it takes, so this PR adds a sensor that reads the values from the remaining time key to show the value but only when the program is not running, as the value will change at the same time the program advances on time and we don't want that.

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

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings April 11, 2026 11:26
@home-assistant
Copy link
Copy Markdown

Hey there @DavidMStraub, @MartinHjelmare, 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 mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from 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 update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Home Connect sensor to expose the selected program’s duration (sourced from BSH.Common.Option.RemainingProgramTime) when the appliance is not actively running a program, complementing the existing “program finish time” sensor.

Changes:

  • Add a dedicated program_duration sensor entity (duration device class) and register it for supported appliance types.
  • Add translation string for the new sensor name.
  • Extend program sensor tests to cover the new duration sensor behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
homeassistant/components/home_connect/sensor.py Introduces HomeConnectProgramDurationSensor, registers it for applicable appliances, and adds its entity description.
homeassistant/components/home_connect/strings.json Adds program_duration translation key for the new sensor’s displayed name.
tests/components/home_connect/test_sensor.py Updates program event fixtures and expected state mappings to validate the new sensor.

Comment thread homeassistant/components/home_connect/sensor.py Outdated
Comment thread homeassistant/components/home_connect/sensor.py
Comment thread homeassistant/components/home_connect/sensor.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 11, 2026 14:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread homeassistant/components/home_connect/sensor.py Outdated
Comment on lines +708 to +711
"""Return true if the sensor is available."""
# We need to override the available property for the duration sensor,
# because it should only be available when a program is not running,
# unlike the HomeConnectProgramSensor.
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

Fix the availability comment to match the actual logic (the sensor is available only when the program is not running).

Suggested change
"""Return true if the sensor is available."""
# We need to override the available property for the duration sensor,
# because it should only be available when a program is not running,
# unlike the HomeConnectProgramSensor.
"""Return true if the base entity is available and the program is not running."""
# Override availability for the duration sensor so it is hidden while
# a program is running, unlike HomeConnectProgramSensor.

Copilot uses AI. Check for mistakes.
Comment on lines +318 to +325
"sensor.dishwasher_program_duration": (
STATE_UNAVAILABLE,
STATE_UNAVAILABLE,
STATE_UNAVAILABLE,
STATE_UNAVAILABLE,
STATE_UNAVAILABLE,
"25",
),
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

Add a test that covers the operation-state transition ordering (e.g., STATUS Ready arriving before/without an updated remaining-time value) to ensure the new duration sensor never briefly reports the last in-run remaining time when it becomes available again.

Copilot uses AI. Check for mistakes.
native_unit_of_measurement=UnitOfTime.SECONDS,
translation_key="program_duration",
appliance_types=(
"CoffeeMaker",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Side note: Would be good to have an enum class in the library for all appliance types.

Comment thread homeassistant/components/home_connect/sensor.py Outdated
@MartinHjelmare
Copy link
Copy Markdown
Member

but only when the program is not running, as the value will change at the same time the program advances on time and we don't want that

I don't understand this fully.

Also, have you considered if we instead can merge the logic for the duration sensor and the time remaining program sensor into the same sensor, eg a single timestamp sensor.

@MartinHjelmare MartinHjelmare marked this pull request as draft April 13, 2026 14:32
@Diegorro98
Copy link
Copy Markdown
Contributor Author

I tried some time ago at #127992, but there were other opinions. That's where that "we don't want that" came from

@MartinHjelmare
Copy link
Copy Markdown
Member

I don't understand what the duration value represents when the program isn't running. Does it represent an estimated duration time of the selected program that can run in the future?

@Diegorro98
Copy link
Copy Markdown
Contributor Author

That's right

@MartinHjelmare
Copy link
Copy Markdown
Member

I think that should be a separate sensor called eg estimated_total_program_time that is always available for the currently selected program.

@Diegorro98
Copy link
Copy Markdown
Contributor Author

Additionally? Or instead of this one?

@MartinHjelmare
Copy link
Copy Markdown
Member

The current one doesn't make sense to me as the value doesn't represent how long time the program has run (the duration), but the estimated total time.

@Diegorro98
Copy link
Copy Markdown
Contributor Author

So you would change the name to estimated total program time and the availability to always?
But the estimated time would change when the program runs, or you mean to freeze the value while it is running?

@MartinHjelmare
Copy link
Copy Markdown
Member

If the value still represents the estimated total time when the program is running, we can update it when the program runs. But it shouldn't update just because of time passing. It should update when the device does a new estimation of the total program time.

I think it will help to collect some data points of the value before, during and at the end of a program, so we can see how the value changes over the course of a program run.

@Diegorro98
Copy link
Copy Markdown
Contributor Author

In my case, the RemainingProgramTime event does report information about how many seconds are remaining for the program to be finished, an it is updated pretty frequently while the program is running.
While it isn't running, the value only updates when the program changes or some options (such half load or start in relative) changes

@MartinHjelmare
Copy link
Copy Markdown
Member

We could round the time to minutes.

@Diegorro98
Copy link
Copy Markdown
Contributor Author

That could work, sure.
So, just to clarify, we should create a new entity that reports the direct value of BSH.Common.Option.RemainingProgramTime, rounded and always available, and the entity from this PR should not be included.
Is that correct?

@MartinHjelmare
Copy link
Copy Markdown
Member

We first need to clarify what the value represents. Does it represent the total time of the program or the remaining time of the program?

See my comment above:
#167976 (comment)

@Diegorro98
Copy link
Copy Markdown
Contributor Author

It does represent the remaining time of the program

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants