Add duration sensor to Home Connect#167976
Add duration sensor to Home Connect#167976Diegorro98 wants to merge 4 commits intohome-assistant:devfrom
Conversation
|
Hey there @DavidMStraub, @MartinHjelmare, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
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_durationsensor 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. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| """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. |
There was a problem hiding this comment.
Fix the availability comment to match the actual logic (the sensor is available only when the program is not running).
| """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. |
| "sensor.dishwasher_program_duration": ( | ||
| STATE_UNAVAILABLE, | ||
| STATE_UNAVAILABLE, | ||
| STATE_UNAVAILABLE, | ||
| STATE_UNAVAILABLE, | ||
| STATE_UNAVAILABLE, | ||
| "25", | ||
| ), |
There was a problem hiding this comment.
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.
| native_unit_of_measurement=UnitOfTime.SECONDS, | ||
| translation_key="program_duration", | ||
| appliance_types=( | ||
| "CoffeeMaker", |
There was a problem hiding this comment.
Side note: Would be good to have an enum class in the library for all appliance types.
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. |
|
I tried some time ago at #127992, but there were other opinions. That's where that "we don't want that" came from |
|
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? |
|
That's right |
|
I think that should be a separate sensor called eg |
|
Additionally? Or instead of this one? |
|
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. |
|
So you would change the name to estimated total program time and the availability to always? |
|
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. |
|
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. |
|
We could round the time to minutes. |
|
That could work, sure. |
|
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: |
|
It does represent the remaining time of the program |
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
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: