Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of cover-tilt in homekit_controller #91631

Merged

Conversation

badewanne1234
Copy link
Contributor

@badewanne1234 badewanne1234 commented Apr 18, 2023

Proposed change

This change fixes the bug of cover-tilt not working in the component homekit_controller.

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

Checklist

  • 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 Black (black --fast homeassistant tests)
  • 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:

@home-assistant
Copy link

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
Copy link

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
Copy link

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!

Jc2k
Jc2k previously requested changes Apr 25, 2023
Copy link
Member

@Jc2k Jc2k left a comment

Choose a reason for hiding this comment

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

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.

@home-assistant home-assistant bot marked this pull request as draft April 25, 2023 16:04
@home-assistant
Copy link

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

Learn more about our pull request process.

@Aloekior
Copy link

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)

@Jc2k
Copy link
Member

Jc2k commented Apr 25, 2023

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.

@badewanne1234
Copy link
Contributor Author

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?

@Jc2k
Copy link
Member

Jc2k commented Apr 25, 2023

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.

Copy link
Contributor Author

@badewanne1234 badewanne1234 left a comment

Choose a reason for hiding this comment

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

Fix of cover-tilt and its tests

@badewanne1234
Copy link
Contributor Author

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 badewanne1234 marked this pull request as ready for review April 30, 2023 18:45
@home-assistant home-assistant bot requested a review from Jc2k April 30, 2023 18:45
@badewanne1234
Copy link
Contributor Author

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

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @badewanne1234 👍

@emontnemery emontnemery dismissed Jc2k’s stale review May 25, 2023 10:41

The requested tests have been added

@emontnemery emontnemery merged commit 393dbb6 into home-assistant:dev May 25, 2023
24 checks passed
@mat-sienczyk
Copy link

When this will be avaliable in HA?

@frenck
Copy link
Member

frenck commented May 25, 2023

@mat-sienczyk next release.

hookedonunix pushed a commit to hookedonunix/home-assistant that referenced this pull request May 26, 2023
* Fix of cover-tilt in homekit_controller

* Fix of cover-tilt and its tests
@github-actions github-actions bot locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cover tilt not working when using HomeKit-Controller with a Somfy TaHoma Box
7 participants