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
This commit is contained in:
J. Nick Koston 2024-01-01 02:14:28 -10:00 committed by GitHub
parent 74e02fe057
commit 41f0eda712
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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."""