Skip to content

Commit bd1b814

Browse files
wedsa5epenet
authored andcommitted
Fix brightness command not sent when in white color mode (home-assistant#150439)
Co-authored-by: epenet <[email protected]>
1 parent c58a188 commit bd1b814

File tree

2 files changed

+55
-7
lines changed

2 files changed

+55
-7
lines changed

homeassistant/components/tuya/light.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,8 +665,11 @@ def turn_on(self, **kwargs: Any) -> None:
665665
},
666666
]
667667

668-
elif ATTR_BRIGHTNESS in kwargs and self._brightness:
669-
brightness = kwargs[ATTR_BRIGHTNESS]
668+
elif self._brightness and (ATTR_BRIGHTNESS in kwargs or ATTR_WHITE in kwargs):
669+
if ATTR_BRIGHTNESS in kwargs:
670+
brightness = kwargs[ATTR_BRIGHTNESS]
671+
else:
672+
brightness = kwargs[ATTR_WHITE]
670673

671674
# If there is a min/max value, the brightness is actually limited.
672675
# Meaning it is actually not on a 0-255 scale.

tests/components/tuya/test_light.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
from typing import Any
56
from unittest.mock import patch
67

78
import pytest
@@ -66,11 +67,58 @@ async def test_platform_setup_no_discovery(
6667
"mock_device_code",
6768
["dj_mki13ie507rlry4r"],
6869
)
70+
@pytest.mark.parametrize(
71+
("turn_on_input", "expected_commands"),
72+
[
73+
(
74+
{
75+
"white": True,
76+
},
77+
[
78+
{"code": "switch_led", "value": True},
79+
{"code": "work_mode", "value": "white"},
80+
{"code": "bright_value_v2", "value": 546},
81+
],
82+
),
83+
(
84+
{
85+
"brightness": 150,
86+
},
87+
[
88+
{"code": "switch_led", "value": True},
89+
{"code": "bright_value_v2", "value": 592},
90+
],
91+
),
92+
(
93+
{
94+
"white": True,
95+
"brightness": 150,
96+
},
97+
[
98+
{"code": "switch_led", "value": True},
99+
{"code": "work_mode", "value": "white"},
100+
{"code": "bright_value_v2", "value": 592},
101+
],
102+
),
103+
(
104+
{
105+
"white": 150,
106+
},
107+
[
108+
{"code": "switch_led", "value": True},
109+
{"code": "work_mode", "value": "white"},
110+
{"code": "bright_value_v2", "value": 592},
111+
],
112+
),
113+
],
114+
)
69115
async def test_turn_on_white(
70116
hass: HomeAssistant,
71117
mock_manager: ManagerCompat,
72118
mock_config_entry: MockConfigEntry,
73119
mock_device: CustomerDevice,
120+
turn_on_input: dict[str, Any],
121+
expected_commands: list[dict[str, Any]],
74122
) -> None:
75123
"""Test turn_on service."""
76124
entity_id = "light.garage_light"
@@ -83,16 +131,13 @@ async def test_turn_on_white(
83131
SERVICE_TURN_ON,
84132
{
85133
"entity_id": entity_id,
86-
"white": 150,
134+
**turn_on_input,
87135
},
88136
)
89137
await hass.async_block_till_done()
90138
mock_manager.send_commands.assert_called_once_with(
91139
mock_device.id,
92-
[
93-
{"code": "switch_led", "value": True},
94-
{"code": "work_mode", "value": "white"},
95-
],
140+
expected_commands,
96141
)
97142

98143

0 commit comments

Comments
 (0)