Add current active program as a sensor in Homeconnect
Breaking change
Proposed change
Type of change
- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [x] 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:
Checklist
- [x] 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:
- [ ] Documentation added/updated for www.home-assistant.io
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 runningpython3 -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:
- [ ] I have reviewed two other open pull requests in this repository.
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 closeCloses the pull request.@home-assistant rename Awesome new titleRenames the pull request.@home-assistant reopenReopen the pull request.@home-assistant unassign home_connectRemoves the current integration label and assignees on the pull request, add the integration domain after the command.@home-assistant add-label needs-more-informationAdd a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.@home-assistant remove-label needs-more-informationRemove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.
There's already a PR (#126157) that adds a select entity for this so you could also change this remotely :)
@joostlek. The mentioned one tackles the way how a program is selected by the user. This one adds a sensor that tells what program is active based on the event received by the API. This is necessary because there are programs that are not user selectable. For example, favorites in coffee makers. Also, there are programs for machine care, cleaning and so on, that will set the operation state to run, without actually producing any coffee. To create automations running only while preparing a coffee, but not while the machine is cleaning itself, it is necessary to receive all states, not only the user selectable ones.
But if I understand BSH keys correctly (I don't own any home connect stuff, I just review code about it) it's the same value we fetch from the API, so then the select entity would show that value I think.
cc @Diegorro98
Yep, I can confirm that it is the same value we fetch for the current program switches and in the future select entity at #126157
At HomeConnectProgramSwitch class: https://github.com/home-assistant/core/blob/cb1e5a24128013b7b19079c738d84bb2aa824c4b/homeassistant/components/home_connect/switch.py#L218-L225
At HomeConnectProgramSelectEntity class at #126157 PR: https://github.com/home-assistant/core/blob/674eeeb7cd2bb45506b900b70cdbafd32991d870/homeassistant/components/home_connect/select.py#L62-L69
PD: BSH_ACTIVE_PROGRAM value:
https://github.com/home-assistant/core/blob/cb1e5a24128013b7b19079c738d84bb2aa824c4b/homeassistant/components/home_connect/const.py#L12
But do we also support those other modes
Depends
There is no support for other programs different than the ones retrieved from the /programs/available endpoint at Home Connect.
I don't know if the programs @boergegrunicke is mentioning that are not selectable are reported thru that endpoint, but if they are reported but not selectable, it will be shown as the entity state with no problem, and if the user tries to select the program, the API will return an error, and it will generate an error log and end there.
@joostlek unfortunately, the select does not even appear for me, so I cannot test the actual behavior. But I can confirm that the /programs/available endpoint mentioned by @Diegorro98 does only deliver user selectable products. Machine Care, Cleaning and so on are not reported there. So I assume, the select would not show things like cleaning the device itself.
That's odd, in my case I can see that Machine Care program is a selectable program for my dishwasher. Are you able to select the program from the Home Connect app?
The dishwasher is another problem, I have to wait, until it decides to connect to Wi-Fi again ... But that's another problem, I will check that later.
For the coffee maker: In the available programs list by the API, there are only "normal" programs, that will output coffee. No machine care, no favorites. In the app, I just realized that the machine care now appears and can be selected (but still no favorites), but only the programs that also could be triggered on the display. For example, the automatic rinsing on device start, cannot be selected in the app, but it shows up while it is running. Also, it shows up in the python library. There are updates for the product ConsumerProducts.CoffeeMaker.Program.CleaningModes.ApplianceOnRinsing.
Now that #126157 has been merged, do you think this sensor entity is still needed?
Yes, because there is still no other way, to find out what the device is doing, for example during rinse on power on (coffee maker), or when a favorite is running, that was started on the device itself.
Good news, I found an awesome solution. Preparing PR! 🚀