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

Prevent toggle from calling stop on covers which do not support it #106848

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

vexofp
Copy link
Contributor

@vexofp vexofp commented Jan 1, 2024

Proposed change

Previously, it was possible for the core CoverEntity implementation of toggle() to call stop_cover(), even when the entity's supported_features did not include CoverEntityFeature.STOP. (#106791) The default implementation of stop_cover() was a no-op, so this ended up just doing nothing.

This could only happen in the case where the entity without STOP support still reported an opening/closing transitional state, which is presumably unusual? The cover tests and the existing MockCover assumed that the two went hand-in-hand, at least. Nonetheless, a search turned up the following integrations where this case appears possible

  • opengarage
  • smartthings
  • gogogate2
  • modbus
  • linear_garage_door
  • brunt
  • tailwind

I updated the core CoverEntity to map toggle() while opening/closing to close_cover()/open_cover(), respectively, when stop_cover() is not available. This seems like the most reasonable interpretation of that intent under the circumstances?

I also added support to MockCover and the tests for this case.

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

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

home-assistant bot commented Jan 1, 2024

Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration (cover) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of cover 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 cover Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
Member

@bdraco bdraco left a comment

Choose a reason for hiding this comment

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

LGTM. Would like another set of 👀 before merging

@bdraco bdraco changed the title Prevent toggle from calling stop on covers which do not support it. Prevent toggle from calling stop on covers which do not support it Jan 3, 2024
@edenhaus edenhaus added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Jan 3, 2024
@home-assistant home-assistant bot marked this pull request as draft January 3, 2024 09:21
@home-assistant
Copy link

home-assistant bot commented Jan 3, 2024

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.

@MartinHjelmare MartinHjelmare removed the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Jan 3, 2024
@vexofp vexofp marked this pull request as ready for review January 7, 2024 04:50
@@ -481,7 +481,7 @@ async def async_toggle_tilt(self, **kwargs: Any) -> None:
def _get_toggle_function(
self, fns: dict[str, Callable[_P, _R]]
) -> Callable[_P, _R]:
if CoverEntityFeature.STOP | self.supported_features and (
if CoverEntityFeature.STOP in self.supported_features and (
Copy link
Member

Choose a reason for hiding this comment

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

If we want to use in for the check instead of the bitwise operator & we need to implement supported_features_compat, and use that instead.

Example:

def supported_features_compat(self) -> ClimateEntityFeature:

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's then just use & here for now. Changing CoverEntityFeature to support in can be done in a follow-up.

@home-assistant home-assistant bot marked this pull request as draft January 7, 2024 08:44
@emontnemery emontnemery added this to the 2024.1.3 milestone Jan 8, 2024
@emontnemery emontnemery marked this pull request as ready for review January 8, 2024 15:51
@MartinHjelmare MartinHjelmare merged commit 3c53693 into home-assistant:dev Jan 9, 2024
53 checks passed
tomaszsluszniak pushed a commit to tomaszsluszniak/core that referenced this pull request Jan 9, 2024
…ome-assistant#106848)

* Prevent toggle from calling stop on covers which do not support it

* Update homeassistant/components/cover/__init__.py

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2024
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 toggle incorrectly calls stop when not supported
6 participants