mirror of
https://github.com/home-assistant/core.git
synced 2026-09-13 20:20:10 +01:00
Use library min/max kelvin in Tuya lights (#181720)
This commit is contained in:
@@ -8,6 +8,7 @@ from tuya_device_handlers.definition.light import (
|
||||
LightDefinition,
|
||||
get_default_definition,
|
||||
)
|
||||
from tuya_device_handlers.device_wrapper.light import ColorTempWrapper
|
||||
from tuya_sharing import CustomerDevice, Manager
|
||||
|
||||
from homeassistant.components.light import (
|
||||
@@ -426,8 +427,8 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
|
||||
|
||||
_white_color_mode = ColorMode.COLOR_TEMP
|
||||
_fixed_color_mode: ColorMode | None = None
|
||||
_attr_min_color_temp_kelvin = 2000 # 500 Mireds
|
||||
_attr_max_color_temp_kelvin = 6500 # 153 Mireds
|
||||
_attr_min_color_temp_kelvin = ColorTempWrapper.MIN_KELVIN
|
||||
_attr_max_color_temp_kelvin = ColorTempWrapper.MAX_KELVIN
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -453,8 +454,12 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
|
||||
color_modes.add(ColorMode.HS)
|
||||
|
||||
# Check if the light has color temperature
|
||||
if definition.color_temp_wrapper:
|
||||
if color_temp_wrapper := definition.color_temp_wrapper:
|
||||
color_modes.add(ColorMode.COLOR_TEMP)
|
||||
# LightDefinition types the wrapper as a plain DeviceWrapper[int]
|
||||
if isinstance(color_temp_wrapper, ColorTempWrapper):
|
||||
self._attr_min_color_temp_kelvin = color_temp_wrapper.min_kelvin
|
||||
self._attr_max_color_temp_kelvin = color_temp_wrapper.max_kelvin
|
||||
# If light has color but does not have color_temp, check if it has
|
||||
# work_mode "white"
|
||||
elif (
|
||||
|
||||
@@ -5,12 +5,15 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from tuya_device_handlers.device_wrapper.light import ColorTempWrapper
|
||||
from tuya_sharing import CustomerDevice, Manager
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_HS_COLOR,
|
||||
ATTR_MAX_COLOR_TEMP_KELVIN,
|
||||
ATTR_MIN_COLOR_TEMP_KELVIN,
|
||||
ATTR_WHITE,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
@@ -167,3 +170,23 @@ async def test_action(
|
||||
mock_device.id,
|
||||
expected_commands,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mock_device_code", ["dj_ilddqqih3tucdk68"])
|
||||
async def test_color_temp_range_override(
|
||||
hass: HomeAssistant,
|
||||
mock_manager: Manager,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_device: CustomerDevice,
|
||||
) -> None:
|
||||
"""Test the entity reports the Kelvin range exposed by the wrapper."""
|
||||
with (
|
||||
patch.object(ColorTempWrapper, "min_kelvin", 1600),
|
||||
patch.object(ColorTempWrapper, "max_kelvin", 4000),
|
||||
):
|
||||
await initialize_entry(hass, mock_manager, mock_config_entry, mock_device)
|
||||
|
||||
state = hass.states.get("light.ieskas")
|
||||
assert state is not None
|
||||
assert state.attributes[ATTR_MIN_COLOR_TEMP_KELVIN] == 1600
|
||||
assert state.attributes[ATTR_MAX_COLOR_TEMP_KELVIN] == 4000
|
||||
|
||||
Reference in New Issue
Block a user