From 7461af68b983e5f376ae5e2cc7026d338bd62e58 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 3 Sep 2021 17:41:32 +0200 Subject: [PATCH] Use NamedTuple for color temperature range (#55626) --- homeassistant/components/tplink/light.py | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index 6d497812261..17e2b03b790 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -66,16 +66,24 @@ LIGHT_SYSINFO_IS_COLOR = "is_color" MAX_ATTEMPTS = 300 SLEEP_TIME = 2 -TPLINK_KELVIN = { - "LB130": (2500, 9000), - "LB120": (2700, 6500), - "LB230": (2500, 9000), - "KB130": (2500, 9000), - "KL130": (2500, 9000), - "KL125": (2500, 6500), - r"KL120\(EU\)": (2700, 6500), - r"KL120\(US\)": (2700, 5000), - r"KL430\(US\)": (2500, 9000), + +class ColorTempRange(NamedTuple): + """Color temperature range (in Kelvin).""" + + min: int + max: int + + +TPLINK_KELVIN: dict[str, ColorTempRange] = { + "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 @@ -294,7 +302,7 @@ class TPLinkSmartBulb(LightEntity): """Flag 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: White temperature range in Kelvin (minimum, maximum) @@ -305,7 +313,7 @@ class TPLinkSmartBulb(LightEntity): return temp_range # pyHS100 is abandoned, but some bulb definitions aren't present # 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: """Determine all supported features in one go.""" @@ -323,9 +331,9 @@ class TPLinkSmartBulb(LightEntity): supported_features += SUPPORT_BRIGHTNESS if sysinfo.get(LIGHT_SYSINFO_IS_VARIABLE_COLOR_TEMP): supported_features += SUPPORT_COLOR_TEMP - max_range, min_range = self._get_valid_temperature_range() - min_mireds = kelvin_to_mired(min_range) - max_mireds = kelvin_to_mired(max_range) + color_temp_range = self._get_valid_temperature_range() + min_mireds = kelvin_to_mired(color_temp_range.max) + max_mireds = kelvin_to_mired(color_temp_range.min) if sysinfo.get(LIGHT_SYSINFO_IS_COLOR): supported_features += SUPPORT_COLOR