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

Add ColorMode.WHITE when Tuya bulbs support white but don't have temp_value #126242

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

wedsa5
Copy link

@wedsa5 wedsa5 commented Sep 19, 2024

Tuya: Add ColorMode.WHITE when bulb supports white but doesn't have temp_value

Breaking change

N/A

Proposed change

Tuya bulbs that support a white color mode but don't have adjustable white color temp were broken several versions of HA ago. See this large thread.

I added a check after the check for color temp to check if the bulb supports work_mode white. If the bulb does not support color_temp, but it still supports white work_mode, I will add ColorMode.WHITE to the list of supported color_modes. I also added a new entity value _white_color_mode which will hold the color mode corresponding to how the bulb supports white. It will either be WHITE or COLOR_TEMP.

Modified the turn_on function to check for ATTR_WHITE as well as ATTR_COLOR_TEMP in determining if the command should include setting the work_mode to WHITE. If the _white_color_mode is COLOR_TEMP, it will also set the color temp in the commands.

Modified the color_mode function to return the _white_color_mode when the work_mode is white. Again, this can be either WHITE or COLOR_TEMP.

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.

To help with the load of incoming pull requests:

home-assistant[bot]

This comment was marked as outdated.

@home-assistant
Copy link

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

Code owner commands

Code owners of tuya 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 tuya 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.

@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from afc2cc2 to f8e609d Compare September 19, 2024 03:33
home-assistant[bot]

This comment was marked as resolved.

@wedsa5
Copy link
Author

wedsa5 commented Sep 19, 2024

This is very much a draft and needs more testing with other bulbs. I have tried to avoid any breaking changes though. I will clean up the logging and comments later.

home-assistant[bot]

This comment was marked as outdated.

@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from ba38808 to 3179b95 Compare September 19, 2024 04:12
home-assistant[bot]

This comment was marked as outdated.

@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from 6f30e16 to 5170faf Compare September 19, 2024 04:25
@MartinHjelmare MartinHjelmare changed the title Tuya: Add ColorMode.WHITE when bulb supports white but doesn't have temp_value Add ColorMode.WHITE when Tuya bulbs support white but don't have temp_value Sep 19, 2024
@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch 3 times, most recently from 62d0f15 to 8f5f868 Compare September 19, 2024 22:12
@wedsa5 wedsa5 marked this pull request as ready for review September 19, 2024 22:12
@wedsa5 wedsa5 requested a review from frenck as a code owner September 19, 2024 22:12
@wedsa5
Copy link
Author

wedsa5 commented Sep 19, 2024

Functional testing has been completed by myself and @bartplessers.

@wedsa5

This comment was marked as off-topic.

@reinikainen

This comment was marked as off-topic.

@wedsa5

This comment was marked as off-topic.

@talondnb

This comment was marked as off-topic.

@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from e8df5f5 to ef1a431 Compare February 3, 2025 21:00
@wedsa5

This comment was marked as off-topic.

@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from ef1a431 to 3cb0373 Compare February 13, 2025 17:03
@wedsa5
Copy link
Author

wedsa5 commented Feb 13, 2025

I am going to attempt to reset the reviewers by reverting to draft and possibly re-opening the PR. we'll see how that goes.

@wedsa5
Copy link
Author

wedsa5 commented Feb 13, 2025

reopening this PR because it has more comments/reactions and is more likely to get reviewed/merged.

The other one i tried opening had no reviewers.

@wedsa5 wedsa5 reopened this Feb 13, 2025
@wedsa5 wedsa5 marked this pull request as ready for review February 13, 2025 17:35
@klier

This comment was marked as off-topic.

@opiper

This comment was marked as off-topic.

@Soarnoa

This comment was marked as off-topic.

@frenck
Copy link
Member

frenck commented Mar 3, 2025

I really, really, really strongly want everybody to stop pinging everyone and asking for reviews and/or complaining. All it does is drive people away. In my personal case, it caused me to fully mute this PR, as the only thing I got was noise in my notifications.

Please keep PR comments to review the contents of the pull request. If you want to discuss other things, use our community forums or Discord chat.

I've marked every unrelated comment as off-topic; and resolved a few that have been handled at this point.

../Frenck

@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from 73782be to 21d183c Compare March 5, 2025 19:04
@wedsa5 wedsa5 force-pushed the tuya-light-white-color-mode-fix branch from 21d183c to 328dc7c Compare March 11, 2025 17:02
@bartplessers
Copy link

bartplessers commented Mar 12, 2025

@wedsa5 : HELP!
I upgraded today to HA 2025.3.2
I used your fix for my tuya lights
However, after upgrading "some" lights do NOT get update status from Tuya.

So my current situation is

  • a light that supports brightness and white with color temp (but no color)
  • I can turn light on/off with tuya app
  • I can turn light on/off with official tuya integration in HA
  • I can toggle light just once with your tuya hotfix integration because
    • when I reload custom integration: status of lights is correctly displayed in HA
    • I toggle light in HA --> light will effectively be toggled
    • but the new status is NOT reflected anymore in HA

This behavior does not occur in the official Tuya integration.
(but there the original problem stil remains: light with color, but no colortemp can not be dimmed )

So I'm a but stuck now :-(
I downgraded HA, and found this problem was introduced in HA2025.3.0. On HA2025.2.5 your fix is still working...

Would you mind taking a closer look at this?

kind regards,
bartplessers

@wedsa5
Copy link
Author

wedsa5 commented Mar 12, 2025

@wedsa5 : HELP! I upgraded today to HA 2025.3.2 I used your fix for my tuya lights However, after upgrading "some" lights do NOT get update status from Tuya.

Hey, I noticed the same issue on my end. I suspected it was due to some changes with the core Tuya integration that conflicted with my changes that I resolved in my branch a while ago. It seems that was introduced in 2025.3.

The solution for me was to re-download and re-install the latest version of my branch as a custom component again since it has changed since I first wrote it (and since you first installed it as a custom component).

If you already did this after 2025.3, then it must be another issue. Since you didn't say you re-downloaded and re-installed, when you said you "reloaded" the custom integration I assume you mean the reload button from the UI.

-wedsa5

@bartplessers
Copy link

bartplessers commented Mar 13, 2025

The solution for me was to re-download and re-install the latest version of my branch as a custom component

Hero!

This is what I had to do to get things up and running again...

STEP 1
downloaded
https://github.com/home-assistant/core/tree/2025.3.2
as a zip file

STEP 2
unzipped, and copied directory
\core-2025.3.2\homeassistant\components\tuya

to my home assistant instance
\config\custom_components\tuya

STEP 3
modified manifest.json and added following line:
"version": "2025.3.0",

STEP 4
downloaded light.py from
https://github.com/home-assistant/core/blob/328dc7c0e0a49b04560643eae4bf5e58db931880/homeassistant/components/tuya/light.py

and placed file into directory
\config\custom_components\tuya

STEP 5
restarted HA

@bartplessers
Copy link

@wedsa5 ,
I noticed another bug now:

For lights with white + color, the "presets" (1) work fine
2025-03-13_22-21-01

However, using a preset on a light with white + colortemp (but no color), this generates an error...
2025-03-13_22-22-30

On the OOB tuya integration shipped with HA 2025.3.2, this problem does not occur...

grtz
B

@wedsa5
Copy link
Author

wedsa5 commented Mar 14, 2025

However, using a preset on a light with white + colortemp (but no color), this generates an error... !

On the OOB tuya integration shipped with HA 2025.3.2, this problem does not occur...

Does this occur with the custom integration prior to 2025.3.x?

If it does, then it's something inherently wrong with the fix. If not, then it is something that is incompatible with 2025.3.x combined with the fix. Unfortunately, I don't own a tuya bulb with color temp so I can't test it on my own. You will probably need to upload a diagnostic so I can take a look when I'm able to look.

@bartplessers
Copy link

Hi @wedsa5

Problem is that the current light.py is NOT compatible with the tuya integration prior to 2025.3.0

So if I:

STEP 0
downgraded HA to 2025.2.5

STEP 1
downloaded
https://github.com/home-assistant/core/tree/2025.2.5
as a zip file

STEP 2
unzipped, and copied directory
\core-2025.2.5\homeassistant\components\tuya

to my home assistant instance
\config\custom_components\tuya

STEP 3
modified manifest.json and added following line:
"version": "2025.2.5",

STEP 4
downloaded light.py from
https://github.com/home-assistant/core/blob/328dc7c0e0a49b04560643eae4bf5e58db931880/homeassistant/components/tuya/light.py

and placed file into directory
\config\custom_components\tuya

STEP 5
restarted HA

Then I receive following error:

2025-03-15_11-34-46

Logger: homeassistant.config_entries
Source: config_entries.py:637
First occurred: 11:28:29 AM (1 occurrences)
Last logged: 11:28:29 AM

Error setting up entry plessers@gmail.com for tuya
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 637, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/tuya/__init__.py", line 95, in async_setup_entry
    await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2272, in async_forward_entry_setups
    await integration.async_get_platforms(platforms)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1185, in async_get_platforms
    import_future.result()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1185, in async_get_platforms
    import_future.result()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1185, in async_get_platforms
    import_future.result()
    ~~~~~~~~~~~~~~~~~~~~^^
  [Previous line repeated 13 more times]
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1173, in async_get_platforms
    platforms.update(self._load_platforms(platform_names))
                     ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1098, in _load_platforms
    platform_name: self._load_platform(platform_name)
                   ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1272, in _load_platform
    cache[full_name] = self._import_platform(platform_name)
                       ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 1304, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/util/loop.py", line 201, in protected_loop_func
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.13/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 1026, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/tuya/light.py", line 24, in <module>
    from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
ImportError: cannot import name 'AddConfigEntryEntitiesCallback' from 'homeassistant.helpers.entity_platform' (/usr/src/homeassistant/homeassistant/helpers/entity_platform.py)

So, I can you provide me with a light.py-file that is compatible with 2025.2.5?

kind regards,
Bart plessers

@bartplessers
Copy link

bartplessers commented Mar 15, 2025

PS
For now, I downgraded my tuya integration to 2024.3.3 (last known working version).
However:

  • It seems that this tuya version works with HA 2025.2.5, although you don't have the ability to swith from color mode to white mode. But at least I can dim my kitchen lights again without introducing a color spectacle... ;-)
  • but this integration does NOT work with HA 2025.3.x

so I'm a bit stuck now :-(

@bartplessers
Copy link

bartplessers commented Mar 15, 2025

Hi @wedsa5 ,

Went digging into my archives, I found some old "light.py" files.

After elaborate testing, I found following:

  • HA 2025.3.1 + tuya_2025.3.2 + custom light.py.2024-09-21 --> OK
  • HA 2025.3.2 + tuya_2025.3.2 + custom light.py.2024-09-21 --> OK
  • HA 2025.3.3 + tuya_2025.3.2 + custom light.py.2024-09-21 --> OK
  • HA 2025.3.3 + tuya_2025.3.3 + custom light.py.2024-09-21 --> OK
  • HA 2025.3.3 + tuya_2025.3.3 + custom light.py.2025-03-11 --> NOT OK

Also:

  • HA 2025.3.x + tuya_2025.2.x --> NOT OK (if you modify local manifest.json and add "version", Tuya won't start)

So conclusion

For your reference, I add some files here:

And If you want to take a closer look, here also the diagnostics of some bulbs

  • 00.00.01 spot 1 --> White + Temperature
  • 00.00.03 spot 1 --> White + Temperature + Color
  • 00.03 keuken uplight 1 --> White + Color
    config_files.zip

kind regards,
Bart Plessers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2024.4 Tuya integration: lights white/color mode not updated