core icon indicating copy to clipboard operation
core copied to clipboard

Fix of cover-tilt in homekit_controller

Open badewanne1234 opened this issue 2 years ago • 9 comments

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:

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.
  • [ ] Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

badewanne1234 avatar Apr 18 '23 19:04 badewanne1234

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!

home-assistant[bot] avatar Apr 18 '23 19:04 home-assistant[bot]

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 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 homekit_controller Removes the current integration label and assignees on the pull request, add the integration domain after the command.

home-assistant[bot] avatar Apr 18 '23 19:04 home-assistant[bot]

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!

home-assistant[bot] avatar Apr 18 '23 19:04 home-assistant[bot]

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1:

Learn more about our pull request process.

home-assistant[bot] avatar Apr 25 '23 16:04 home-assistant[bot]

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)

L-i-v-y avatar Apr 25 '23 16:04 L-i-v-y

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.

Jc2k avatar Apr 25 '23 16:04 Jc2k

In the tests you will see create_window_covering_service_with_h_tilt and create_window_covering_service_with_v_tilt. These have default values for minValue and maxValue.

This means that you are only testing the 0.9 cases and NOT the -0.9 case.

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.9 so 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?

badewanne1234 avatar Apr 25 '23 19:04 badewanne1234

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.

Jc2k avatar Apr 25 '23 20:04 Jc2k

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 :)

badewanne1234 avatar Apr 30 '23 18:04 badewanne1234

Is there anything still missing from my side for the review?

badewanne1234 avatar May 16 '23 18:05 badewanne1234

When this will be avaliable in HA?

mat-sienczyk avatar May 25 '23 15:05 mat-sienczyk

@mat-sienczyk next release.

frenck avatar May 25 '23 15:05 frenck