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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Z-Wave JS cover stop support #78723

Merged
merged 2 commits into from
Nov 16, 2022

Conversation

Yukon
Copy link
Contributor

@Yukon Yukon commented Sep 19, 2022

Proposed change

This change fixes issues stopping covers (blinds) I was having with my home setup. The Z-Wave JS integration would blindly set the Up/Down property twice, causing the blinds to move again. The integration will now only stop one direction which will stop the cover regardless of actual direction of travel.

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

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
  • 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.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 馃 Silver
  • 馃 Gold
  • 馃弳 Platinum

To help with the load of incoming pull requests:

@Yukon Yukon requested a review from a team as a code owner September 19, 2022 03:38
@homeassistant
Copy link
Contributor

Hi @Yukon,

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!

@probot-home-assistant
Copy link

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

@MartinHjelmare
Copy link
Member

Please make sure the CI checks pass.

Copy link
Contributor

@kpine kpine left a comment

Choose a reason for hiding this comment

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

I don't think this is the right solution. I am fairly certain the root of this problem is it looks like the original implementation was copied from the OZW integration code, which sent multiple open/close commands to workaround a bug in OZW (legacy zwave used a different API so it doesn't have this same code).

The desired Z-Wave command to stop an ongoing multilevel-switch transition is the Multilevel Switch CC Stop Level Command. Any one of the open/up/close/down values set to a False value will result in the stop level command. If there's an Up value, then there's always a Down, Open and Close, etc, so you just need to find one them, e.g. On, Up, Open, etc.

All possible switch types are listed here. Each X/Y entry generates separate "X" and "Y" value IDs.

Another approach to finding a value would be to search all values and find the first that has metadata cc_specific.switch_type (or however the Python lib represents it), and use that one. Or, one could just use the CC API instead (see invoke_cc_api used elsewhere) and manually call the stopLevelChange instead, but you'd also need to check for support.

In summary, the solution should probably be to just remove the duplicate set_value. Your change effectively does this because it returns on the first check.

If you're unsure of how these properties are supposed to work (and don't take my word for it), I would confirm with the node-zwave-js project.

homeassistant/components/zwave_js/cover.py Outdated Show resolved Hide resolved
@Yukon
Copy link
Contributor Author

Yukon commented Oct 2, 2022

Hopefully I can get some feedback from others that have worked with covers about the readable state. It seems to be the case from the additional details @kpine provided that it really does not matter as setting the Open or Close state performs the same action in Wave-JS. I will jump on making that change, hopefully I will be able to figure out what is tripping up the flake8 CI check.

@Yukon Yukon force-pushed the fix_zwave_js_cover_somfy branch 3 times, most recently from 7b2fb36 to 6b2754f Compare October 3, 2022 00:26
@Yukon
Copy link
Contributor Author

Yukon commented Oct 3, 2022

Changes are up! Much simpler approach calling stopLevelChange.

@MartinHjelmare MartinHjelmare self-assigned this Oct 26, 2022
@MartinHjelmare MartinHjelmare removed their assignment Oct 26, 2022
@MartinHjelmare
Copy link
Member

@kpine are you happy with this change?

@kpine
Copy link
Contributor

kpine commented Oct 27, 2022

@kpine are you happy with this change?

Technically, looks fine to me. The "stopLevelChange" command is mandatory for all devices that support the multilevel switch CC, which all the (non-barrier) covers are, so there's no issue using it. The only thing is that by using the CC API it deviates from the convention (value ID API) used elsewhere in the integration, so not sure if that is a problem for you.

I think the same solution would be achieved by just deleting the usage of the close_value value ID in the original code.

@MartinHjelmare
Copy link
Member

@Yukon I'd suggest we follow the suggestion by @kpine and just remove the close_value call and adjust the tests accordingly. This will make the change smaller and should mostly be a deletion of code compared to the dev branch.

Only set one cover property that will send the Multilevel Switch CC Stop Level command.
@Yukon
Copy link
Contributor Author

Yukon commented Nov 13, 2022

@MartinHjelmare The changes have been simplified to just remove the problematic extra stop.

@MartinHjelmare
Copy link
Member

Thanks! Please solve the lint errors.

@frenck
Copy link
Member

frenck commented Nov 16, 2022

Pushed a fix for the linter warnings

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Thanks!

@MartinHjelmare MartinHjelmare added this to the 2022.11.3 milestone Nov 16, 2022
@frenck frenck merged commit 9098592 into home-assistant:dev Nov 16, 2022
frenck added a commit that referenced this pull request Nov 16, 2022
Co-authored-by: Franck Nijhof <git@frenck.dev>
@frenck frenck mentioned this pull request Nov 16, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2022
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.

None yet

5 participants