Use getter names instead of setters

This commit is contained in:
Steven B 2024-11-25 13:36:00 +00:00
parent abc8ea6f4c
commit da83bcc589
No known key found for this signature in database
GPG Key ID: 6D5B46B3679F2A43
2 changed files with 9 additions and 11 deletions

View File

@ -25,11 +25,11 @@ Get the light module to interact:
You can use the ``is_``-prefixed properties to check for supported features: You can use the ``is_``-prefixed properties to check for supported features:
>>> light.has_feature(light.set_brightness) >>> light.has_feature("brightness")
True True
>>> light.has_feature(light.set_hsv) >>> light.has_feature("hsv")
True True
>>> light.has_feature(light.set_color_temp) >>> light.has_feature("color_temp")
True True
All known bulbs support changing the brightness: All known bulbs support changing the brightness:
@ -43,7 +43,7 @@ All known bulbs support changing the brightness:
Bulbs supporting color temperature can be queried for the supported range: Bulbs supporting color temperature can be queried for the supported range:
>>> if color_temp_feature := light.get_feature(light.set_color_temp): >>> if color_temp_feature := light.get_feature("color_temp"):
>>> print(f"{color_temp_feature.minimum_value}, {color_temp_feature.maximum_value}") >>> print(f"{color_temp_feature.minimum_value}, {color_temp_feature.maximum_value}")
2500, 6500 2500, 6500
>>> await light.set_color_temp(3000) >>> await light.set_color_temp(3000)
@ -174,7 +174,7 @@ class Light(Module, ABC):
"""Set the light state.""" """Set the light state."""
def _deprecated_valid_temperature_range(self) -> ColorTempRange: def _deprecated_valid_temperature_range(self) -> ColorTempRange:
if not (temp := self.get_feature(self.set_color_temp)): if not (temp := self.get_feature("color_temp")):
raise KasaException("Color temperature not supported") raise KasaException("Color temperature not supported")
return ColorTempRange(temp.minimum_value, temp.maximum_value) return ColorTempRange(temp.minimum_value, temp.maximum_value)

View File

@ -96,12 +96,10 @@ class LightPreset(SmartModule, LightPresetInterface):
"""Return current preset name.""" """Return current preset name."""
light = self._device.modules[SmartModule.Light] light = self._device.modules[SmartModule.Light]
brightness = light.brightness brightness = light.brightness
color_temp = ( color_temp = light.color_temp if light.has_feature("color_temp") else None
light.color_temp if light.has_feature(light.set_color_temp) else None
)
h, s = ( h, s = (
(light.hsv.hue, light.hsv.saturation) (light.hsv.hue, light.hsv.saturation)
if light.has_feature(light.set_hsv) if light.has_feature("hsv")
else (None, None) else (None, None)
) )
for preset_name, preset in self._presets.items(): for preset_name, preset in self._presets.items():
@ -109,7 +107,7 @@ class LightPreset(SmartModule, LightPresetInterface):
preset.brightness == brightness preset.brightness == brightness
and ( and (
preset.color_temp == color_temp preset.color_temp == color_temp
or not light.has_feature(light.set_color_temp) or not light.has_feature("color_temp")
) )
and preset.hue == h and preset.hue == h
and preset.saturation == s and preset.saturation == s
@ -124,7 +122,7 @@ class LightPreset(SmartModule, LightPresetInterface):
"""Set a light preset for the device.""" """Set a light preset for the device."""
light = self._device.modules[SmartModule.Light] light = self._device.modules[SmartModule.Light]
if preset_name == self.PRESET_NOT_SET: if preset_name == self.PRESET_NOT_SET:
if light.has_feature(light.set_hsv): if light.has_feature("hsv"):
preset = LightState(hue=0, saturation=0, brightness=100) preset = LightState(hue=0, saturation=0, brightness=100)
else: else:
preset = LightState(brightness=100) preset = LightState(brightness=100)