core
core copied to clipboard
Fix of cover-tilt in homekit_controller
Proposed change
This change fixes the bug of cover-tilt not working in the component homekit_controller.
Type of change
- [ ] Dependency upgrade
- [x] 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 #63068
- This PR is related to issue:
- Link to documentation pull request:
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 Black (
black --fast homeassistant tests) - [x] 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.
- [ ] Untested files have been added to
.coveragerc.
To help with the load of incoming pull requests:
- [ ] I have reviewed two other open pull requests in this repository.
Hi @badewanne1234
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Hey there @jc2k, @bdraco, mind taking a look at this pull request as it has been labeled with an integration (homekit_controller) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of homekit_controller 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 homekit_controllerRemoves the current integration label and assignees on the pull request, add the integration domain after the command.
Hi @badewanne1234
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1:
Sorry for barging in on this, but just wondering how +90°/-90° tilts are considered in this fix? Will those work too if there are just separate cases for +90° or -90°? (not entirely sure how they are being reported in Home Assistant since I can't tell if mine have been set up correctly by the technicians, so mine still show up as 0 to -90 in the dev tools)
Not sure what you are asking.
From community testing there are 4 cases - horizontal and vertical and -90 to 0 and 0 to 90.
We just need a scale factor to go from arc degrees to % and back. That's either -0.9 or 0.9.
You either multiply or divide by it, which is what this PR does.
In the tests you will see
create_window_covering_service_with_h_tiltandcreate_window_covering_service_with_v_tilt. These have default values forminValueandmaxValue.This means that you are only testing the
0.9cases and NOT the-0.9case.You need to duplicate both of those functions and change them for the -0.9 case, then duplicate any tests that involve HORIZONTAL_TILT_TARGET or VERTICAL_TILT_TARGET and make those duplicates also test the -0.9 case.
Right now none of the tests run with a scale of
-0.9so they provide no guarantee's that your change has worked.
Thank you. You are right, currently 0.9 is being tested only. To cover tests for -0.9, I think as a non-python-expert, I would need to define the scale variable as a global variable / constant instead of just defining it in each function, so that it can be accessed in the test_cover.py file, then I can modify it accordingly to the tests in the test_cover.py. Is there a place where I have to put this constant in, if its only for the homekit_controller and not for the entire HA core?
No, global variables are typically frowned upon in python and wouldn't pass code review in HA (in general).
The simplest solution is what I said above - duplicate the tests. The tests create a mock device with a 0-90 range and we need variants of those tests that create a device with a -90 to 0 range. The 2 functions I called out are where the fake characteristics are defined so that's where you can provide your own variables for minValue and maxValue.
No, global variables are typically frowned upon in python and wouldn't pass code review in HA (in general).
The simplest solution is what I said above - duplicate the tests. The tests create a mock device with a 0-90 range and we need variants of those tests that create a device with a -90 to 0 range. The 2 functions I called out are where the fake characteristics are defined so that's where you can provide your own variables for minValue and maxValue.
Thank you, you're absolutely right, no need for the global variable. I added additional tests which test against the -0.9 scale, all tests pass :)
Is there anything still missing from my side for the review?
When this will be avaliable in HA?
@mat-sienczyk next release.