From 41f0eda7124619e27057e50c975fa898998088a7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 1 Jan 2024 02:14:28 -1000 Subject: [PATCH] Use shorthand attrs for tplink color temp min/max (#106796) The valid_temperature_range property does a regex match over every possible model. Avoid calling it more than once since it will never change as its based on the model --- homeassistant/components/tplink/light.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index 8e77c68a880..c4ec80347d5 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -185,6 +185,9 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity): modes: set[ColorMode] = set() if device.is_variable_color_temp: modes.add(ColorMode.COLOR_TEMP) + temp_range = device.valid_temperature_range + self._attr_min_color_temp_kelvin = temp_range.min + self._attr_max_color_temp_kelvin = temp_range.max if device.is_color: modes.add(ColorMode.HS) if device.is_dimmable: @@ -251,16 +254,6 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity): transition = int(transition * 1_000) await self.device.turn_off(transition=transition) - @property - def min_color_temp_kelvin(self) -> int: - """Return minimum supported color temperature.""" - return cast(int, self.device.valid_temperature_range.min) - - @property - def max_color_temp_kelvin(self) -> int: - """Return maximum supported color temperature.""" - return cast(int, self.device.valid_temperature_range.max) - @property def color_temp_kelvin(self) -> int: """Return the color temperature of this light."""