Group "assume member state": colour-temperature commands never update members' colour mode

Open Beginner friendly
#858 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
embedded-iot

Research direction

The bug is in _make_members_assume_group_state() in zha/application/platforms/light/init.py, around lines 1582-1594, where the colour-temperature and xy-colour blocks both assign assumed_color_mode. Read the guard that consumes it near lines 1643-1644 to see why colour-temperature commands never switch member mode. Done means a colour-temperature group command sets members' colour mode, while xy commands behave as before; the payload names no test file, so verify the change by tracing that path.

Written by the indexing model from the issue text.

Description

In _make_members_assume_group_state(), the colour-temperature and xy-colour blocks both write assumed_color_mode, and the second unconditionally overwrites the first:

https://github.com/zigpy/zha/blob/dev/zha/application/platforms/light/__init__.py#L1582-L1594

if color_temp is not None:
    assumed_color_mode = self._color_mode
    assumed_color_temp = self._color_temp
else:
    assumed_color_mode = None
    assumed_color_temp = None

if xy_color is not None:
    assumed_color_mode = self._color_mode
    assumed_xy_color = self._xy_color
else:
    assumed_color_mode = None
    assumed_xy_color = None

A colour-temperature command has xy_color is None, so the second else resets assumed_color_mode to None after the first block has just set it.

That value is consumed further down:

https://github.com/zigpy/zha/blob/dev/zha/application/platforms/light/__init__.py#L1643-L1644

if assumed_color_mode is not None and assumed_color_mode in supported_modes:
    platform_entity._color_mode = assumed_color_mode

so the guard fails and members never have their colour mode switched. assumed_color_temp survives and is applied by its own separate guard, so the member ends up with an updated colour temperature while still reporting whatever colour mode it had before.

This only affects the "assume member group state" path, and only for colour-temperature commands — an xy command sets the mode last and is unaffected.

Suggested fix

Only reset assumed_color_mode when neither branch has set it, for example by computing it once from whether either color_temp or xy_color was supplied, rather than assigning it in both blocks.

Found while reading this function for an unrelated reason; not reproduced against hardware.

Dominant language
Python
Stars
96
Forks
84
Avg merge
2d 4h
Merged PRs (30d)
30

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from zigpy/zha

All issues in zigpy/zha

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.