mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use NamedTuple for color temperature range (#55626)
This commit is contained in:
parent
2171922265
commit
7461af68b9
@ -66,16 +66,24 @@ LIGHT_SYSINFO_IS_COLOR = "is_color"
|
|||||||
MAX_ATTEMPTS = 300
|
MAX_ATTEMPTS = 300
|
||||||
SLEEP_TIME = 2
|
SLEEP_TIME = 2
|
||||||
|
|
||||||
TPLINK_KELVIN = {
|
|
||||||
"LB130": (2500, 9000),
|
class ColorTempRange(NamedTuple):
|
||||||
"LB120": (2700, 6500),
|
"""Color temperature range (in Kelvin)."""
|
||||||
"LB230": (2500, 9000),
|
|
||||||
"KB130": (2500, 9000),
|
min: int
|
||||||
"KL130": (2500, 9000),
|
max: int
|
||||||
"KL125": (2500, 6500),
|
|
||||||
r"KL120\(EU\)": (2700, 6500),
|
|
||||||
r"KL120\(US\)": (2700, 5000),
|
TPLINK_KELVIN: dict[str, ColorTempRange] = {
|
||||||
r"KL430\(US\)": (2500, 9000),
|
"LB130": ColorTempRange(2500, 9000),
|
||||||
|
"LB120": ColorTempRange(2700, 6500),
|
||||||
|
"LB230": ColorTempRange(2500, 9000),
|
||||||
|
"KB130": ColorTempRange(2500, 9000),
|
||||||
|
"KL130": ColorTempRange(2500, 9000),
|
||||||
|
"KL125": ColorTempRange(2500, 6500),
|
||||||
|
r"KL120\(EU\)": ColorTempRange(2700, 6500),
|
||||||
|
r"KL120\(US\)": ColorTempRange(2700, 5000),
|
||||||
|
r"KL430\(US\)": ColorTempRange(2500, 9000),
|
||||||
}
|
}
|
||||||
|
|
||||||
FALLBACK_MIN_COLOR = 2700
|
FALLBACK_MIN_COLOR = 2700
|
||||||
@ -294,7 +302,7 @@ class TPLinkSmartBulb(LightEntity):
|
|||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
return self._light_features.supported_features
|
return self._light_features.supported_features
|
||||||
|
|
||||||
def _get_valid_temperature_range(self) -> tuple[int, int]:
|
def _get_valid_temperature_range(self) -> ColorTempRange:
|
||||||
"""Return the device-specific white temperature range (in Kelvin).
|
"""Return the device-specific white temperature range (in Kelvin).
|
||||||
|
|
||||||
:return: White temperature range in Kelvin (minimum, maximum)
|
:return: White temperature range in Kelvin (minimum, maximum)
|
||||||
@ -305,7 +313,7 @@ class TPLinkSmartBulb(LightEntity):
|
|||||||
return temp_range
|
return temp_range
|
||||||
# pyHS100 is abandoned, but some bulb definitions aren't present
|
# pyHS100 is abandoned, but some bulb definitions aren't present
|
||||||
# use "safe" values for something that advertises color temperature
|
# use "safe" values for something that advertises color temperature
|
||||||
return FALLBACK_MIN_COLOR, FALLBACK_MAX_COLOR
|
return ColorTempRange(FALLBACK_MIN_COLOR, FALLBACK_MAX_COLOR)
|
||||||
|
|
||||||
def _get_light_features(self) -> LightFeatures:
|
def _get_light_features(self) -> LightFeatures:
|
||||||
"""Determine all supported features in one go."""
|
"""Determine all supported features in one go."""
|
||||||
@ -323,9 +331,9 @@ class TPLinkSmartBulb(LightEntity):
|
|||||||
supported_features += SUPPORT_BRIGHTNESS
|
supported_features += SUPPORT_BRIGHTNESS
|
||||||
if sysinfo.get(LIGHT_SYSINFO_IS_VARIABLE_COLOR_TEMP):
|
if sysinfo.get(LIGHT_SYSINFO_IS_VARIABLE_COLOR_TEMP):
|
||||||
supported_features += SUPPORT_COLOR_TEMP
|
supported_features += SUPPORT_COLOR_TEMP
|
||||||
max_range, min_range = self._get_valid_temperature_range()
|
color_temp_range = self._get_valid_temperature_range()
|
||||||
min_mireds = kelvin_to_mired(min_range)
|
min_mireds = kelvin_to_mired(color_temp_range.max)
|
||||||
max_mireds = kelvin_to_mired(max_range)
|
max_mireds = kelvin_to_mired(color_temp_range.min)
|
||||||
if sysinfo.get(LIGHT_SYSINFO_IS_COLOR):
|
if sysinfo.get(LIGHT_SYSINFO_IS_COLOR):
|
||||||
supported_features += SUPPORT_COLOR
|
supported_features += SUPPORT_COLOR
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user