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

Use ExecuteIfOff on color cluster for supported bulbs with ZHA #84874

Merged

Conversation

TheJulianJES
Copy link
Contributor

@TheJulianJES TheJulianJES commented Dec 30, 2022

Proposed change

This implements the options -> ExecuteIfOff on the color cluster for supporting Zigbee 3.0 lights.
This option allows the light to receive various color commands while it's still off. It won't turn on when just the color commands are received, but next time it turns on, it'll turn on with the new color.

  • it implements both an options and execute_if_off_supported property in the color channel
  • it implements the following behavior for turn_on:
    • if the user enables ExecuteIfOff (currently via setting options from 0 to 1 through the clusters UI),
    • then the color commands are always sent before the "on" or "move to level with on off" commands
    • otherwise (like before), the color commands are sent after to "on" or "level" commands

The transition parameter for the various move_to_color commands is apparently ignored by the light if it's off.
This is why we can simply re-order how the calls are sent (when ExecuteIfOff is on) without needing to check the HA state for what transition we want to use when.

(@dmulcahey previously implemented a similar behavior on some (now deleted) test branch)

Note: At the moment, this is only supported for single lights. Groups will always default to the old/standard behavior for now. I'll focus on adding group support for "execute if off" in a separate PR.

(The benefit of using that is that transitions to different colors from an off-state are done properly.)

Previous behavior

The behavior from this PR (disabled by default) is still used for older lights which don't support ExecuteIfOff (or when it's disabled):

So the behavior only changes if the lights supports ExecuteIfOff and if it's also enabled.
(Enabling it needs to be done via cluster settings right now. I'll likely add a config entity in a separate PR)

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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hey there @dmulcahey, @Adminiuga, @puddly, mind taking a look at this pull request as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of zha can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign zha Removes the current integration label and assignees on the issue, add the integration domain after the command.

@@ -45,6 +45,7 @@ class ColorChannel(ZigbeeChannel):
"color_capabilities": True,
"color_loop_active": False,
"start_up_color_temperature": True,
"options": True,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Explanation/Note:

Technically initializing this attribute isn't really needed at the moment, as the options parameter needs to be set manually anyway (for now) and the options property defaults to 0 if there isn't a cached attribute.

In the future, when a configuration entity is added for this attribute, it would be nice if that attribute was already read/initialized (so the configuration entity is created appropriately). (Hence why I added it here (cached, as it won't ever update on its own))

Comment on lines +1250 to +1270
assert dev1_cluster_on_off.request.call_args_list[0] == call(
False,
dev1_cluster_on_off.commands_by_name["on"].id,
dev1_cluster_on_off.commands_by_name["on"].schema,
expect_reply=True,
manufacturer=None,
tries=1,
tsn=None,
)
assert dev1_cluster_color.request.call_args == call(
False,
dev1_cluster_color.commands_by_name["move_to_color_temp"].id,
dev1_cluster_color.commands_by_name["move_to_color_temp"].schema,
color_temp_mireds=235,
transition_time=0,
expect_reply=True,
manufacturer=None,
tries=1,
tsn=None,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question regarding tests:

It's not too important here, but how would I check the message order? (messages are sent on different clusters)
(That code doesn't care whether "on" or "move_to_color_temp" is sent first)

@TheJulianJES
Copy link
Contributor Author

TheJulianJES commented Dec 31, 2022

EDIT: Removed group support from this PR now. I'll likely work on it in a separate PR. The old/standard behavior is still used for groups (even if all lights have "execute if off" enabled).

The latest commit 7019f71 is uh, "experimental", but it successfully adds execute_if_off support for groups if all members support it.

If the group support doesn't work out in a better way here, I'll revert that part (but it would be really nice to have).

Group support will likely be added in a separate PR. For now, the old/standard behavior is used for groups.
@TheJulianJES TheJulianJES marked this pull request as ready for review January 16, 2023 17:55
@TheJulianJES
Copy link
Contributor Author

This should be ready for a review now.

I've removed the group stuff from this PR and will focus on that in a separate PR at some point.
(I'll also look at adding a config entity for turning on/off the "execute if off" attribute/option without using the clusters UI in another PR.)

@dmulcahey dmulcahey merged commit 6582ee3 into home-assistant:dev Jan 23, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 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.

None yet

4 participants