Fix brightness command not sent when in white color mode (#150439)

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
wedsa5
2025-08-12 08:36:52 -06:00
committed by GitHub
parent 711afa306c
commit 07930b12d0
2 changed files with 55 additions and 7 deletions

View File

@@ -663,8 +663,11 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
}, },
] ]
elif ATTR_BRIGHTNESS in kwargs and self._brightness: elif self._brightness and (ATTR_BRIGHTNESS in kwargs or ATTR_WHITE in kwargs):
brightness = kwargs[ATTR_BRIGHTNESS] if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS]
else:
brightness = kwargs[ATTR_WHITE]
# If there is a min/max value, the brightness is actually limited. # If there is a min/max value, the brightness is actually limited.
# Meaning it is actually not on a 0-255 scale. # Meaning it is actually not on a 0-255 scale.

View File

@@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from typing import Any
from unittest.mock import patch from unittest.mock import patch
import pytest import pytest
@@ -42,11 +43,58 @@ async def test_platform_setup_and_discovery(
"mock_device_code", "mock_device_code",
["dj_mki13ie507rlry4r"], ["dj_mki13ie507rlry4r"],
) )
@pytest.mark.parametrize(
("turn_on_input", "expected_commands"),
[
(
{
"white": True,
},
[
{"code": "switch_led", "value": True},
{"code": "work_mode", "value": "white"},
{"code": "bright_value_v2", "value": 546},
],
),
(
{
"brightness": 150,
},
[
{"code": "switch_led", "value": True},
{"code": "bright_value_v2", "value": 592},
],
),
(
{
"white": True,
"brightness": 150,
},
[
{"code": "switch_led", "value": True},
{"code": "work_mode", "value": "white"},
{"code": "bright_value_v2", "value": 592},
],
),
(
{
"white": 150,
},
[
{"code": "switch_led", "value": True},
{"code": "work_mode", "value": "white"},
{"code": "bright_value_v2", "value": 592},
],
),
],
)
async def test_turn_on_white( async def test_turn_on_white(
hass: HomeAssistant, hass: HomeAssistant,
mock_manager: ManagerCompat, mock_manager: ManagerCompat,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
mock_device: CustomerDevice, mock_device: CustomerDevice,
turn_on_input: dict[str, Any],
expected_commands: list[dict[str, Any]],
) -> None: ) -> None:
"""Test turn_on service.""" """Test turn_on service."""
entity_id = "light.garage_light" entity_id = "light.garage_light"
@@ -59,16 +107,13 @@ async def test_turn_on_white(
SERVICE_TURN_ON, SERVICE_TURN_ON,
{ {
"entity_id": entity_id, "entity_id": entity_id,
"white": 150, **turn_on_input,
}, },
) )
await hass.async_block_till_done() await hass.async_block_till_done()
mock_manager.send_commands.assert_called_once_with( mock_manager.send_commands.assert_called_once_with(
mock_device.id, mock_device.id,
[ expected_commands,
{"code": "switch_led", "value": True},
{"code": "work_mode", "value": "white"},
],
) )