mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add Option For Kelvin Unit To Color Temperature Selector (#103799)
This commit is contained in:
parent
d9c0acc1d2
commit
31cab5803c
@ -252,8 +252,9 @@ turn_on:
|
||||
- light.ColorMode.RGBWW
|
||||
selector:
|
||||
color_temp:
|
||||
min_mireds: 153
|
||||
max_mireds: 500
|
||||
unit: "mired"
|
||||
min: 153
|
||||
max: 500
|
||||
kelvin:
|
||||
filter:
|
||||
attribute:
|
||||
@ -266,11 +267,10 @@ turn_on:
|
||||
- light.ColorMode.RGBWW
|
||||
advanced: true
|
||||
selector:
|
||||
number:
|
||||
color_temp:
|
||||
unit: "kelvin"
|
||||
min: 2000
|
||||
max: 6500
|
||||
step: 100
|
||||
unit_of_measurement: K
|
||||
brightness:
|
||||
filter:
|
||||
attribute:
|
||||
@ -637,11 +637,10 @@ toggle:
|
||||
- light.ColorMode.RGBWW
|
||||
advanced: true
|
||||
selector:
|
||||
number:
|
||||
color_temp:
|
||||
unit: "kelvin"
|
||||
min: 2000
|
||||
max: 6500
|
||||
step: 100
|
||||
unit_of_measurement: K
|
||||
brightness:
|
||||
filter:
|
||||
attribute:
|
||||
|
@ -425,10 +425,20 @@ class ColorRGBSelector(Selector[ColorRGBSelectorConfig]):
|
||||
class ColorTempSelectorConfig(TypedDict, total=False):
|
||||
"""Class to represent a color temp selector config."""
|
||||
|
||||
unit: ColorTempSelectorUnit
|
||||
min: int
|
||||
max: int
|
||||
max_mireds: int
|
||||
min_mireds: int
|
||||
|
||||
|
||||
class ColorTempSelectorUnit(StrEnum):
|
||||
"""Possible units for a color temperature selector."""
|
||||
|
||||
KELVIN = "kelvin"
|
||||
MIRED = "mired"
|
||||
|
||||
|
||||
@SELECTORS.register("color_temp")
|
||||
class ColorTempSelector(Selector[ColorTempSelectorConfig]):
|
||||
"""Selector of an color temperature."""
|
||||
@ -437,6 +447,11 @@ class ColorTempSelector(Selector[ColorTempSelectorConfig]):
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional("unit", default=ColorTempSelectorUnit.MIRED): vol.All(
|
||||
vol.Coerce(ColorTempSelectorUnit), lambda val: val.value
|
||||
),
|
||||
vol.Optional("min"): vol.Coerce(int),
|
||||
vol.Optional("max"): vol.Coerce(int),
|
||||
vol.Optional("max_mireds"): vol.Coerce(int),
|
||||
vol.Optional("min_mireds"): vol.Coerce(int),
|
||||
}
|
||||
@ -448,11 +463,20 @@ class ColorTempSelector(Selector[ColorTempSelectorConfig]):
|
||||
|
||||
def __call__(self, data: Any) -> int:
|
||||
"""Validate the passed selection."""
|
||||
range_min = self.config.get("min")
|
||||
range_max = self.config.get("max")
|
||||
|
||||
if not range_min:
|
||||
range_min = self.config.get("min_mireds")
|
||||
|
||||
if not range_max:
|
||||
range_max = self.config.get("max_mireds")
|
||||
|
||||
value: int = vol.All(
|
||||
vol.Coerce(float),
|
||||
vol.Range(
|
||||
min=self.config.get("min_mireds"),
|
||||
max=self.config.get("max_mireds"),
|
||||
min=range_min,
|
||||
max=range_max,
|
||||
),
|
||||
)(data)
|
||||
return value
|
||||
|
@ -907,6 +907,16 @@ def test_rgb_color_selector_schema(
|
||||
(100, 200),
|
||||
(99, 201),
|
||||
),
|
||||
(
|
||||
{"unit": "mired", "min": 100, "max": 200},
|
||||
(100, 200),
|
||||
(99, 201),
|
||||
),
|
||||
(
|
||||
{"unit": "kelvin", "min": 1000, "max": 2000},
|
||||
(1000, 2000),
|
||||
(999, 2001),
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_color_tempselector_schema(
|
||||
|
Loading…
x
Reference in New Issue
Block a user