From da83bcc58968f7d715266ad36bbda4e6f5a809d2 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:36:00 +0000 Subject: [PATCH] Use getter names instead of setters --- kasa/interfaces/light.py | 10 +++++----- kasa/smart/modules/lightpreset.py | 10 ++++------ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/kasa/interfaces/light.py b/kasa/interfaces/light.py index 161c0f21..912ec2e2 100644 --- a/kasa/interfaces/light.py +++ b/kasa/interfaces/light.py @@ -25,11 +25,11 @@ Get the light module to interact: You can use the ``is_``-prefixed properties to check for supported features: ->>> light.has_feature(light.set_brightness) +>>> light.has_feature("brightness") True ->>> light.has_feature(light.set_hsv) +>>> light.has_feature("hsv") True ->>> light.has_feature(light.set_color_temp) +>>> light.has_feature("color_temp") True 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: ->>> 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}") 2500, 6500 >>> await light.set_color_temp(3000) @@ -174,7 +174,7 @@ class Light(Module, ABC): """Set the light state.""" 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") return ColorTempRange(temp.minimum_value, temp.maximum_value) diff --git a/kasa/smart/modules/lightpreset.py b/kasa/smart/modules/lightpreset.py index 63805cf7..87e96eae 100644 --- a/kasa/smart/modules/lightpreset.py +++ b/kasa/smart/modules/lightpreset.py @@ -96,12 +96,10 @@ class LightPreset(SmartModule, LightPresetInterface): """Return current preset name.""" light = self._device.modules[SmartModule.Light] brightness = light.brightness - color_temp = ( - light.color_temp if light.has_feature(light.set_color_temp) else None - ) + color_temp = light.color_temp if light.has_feature("color_temp") else None h, s = ( (light.hsv.hue, light.hsv.saturation) - if light.has_feature(light.set_hsv) + if light.has_feature("hsv") else (None, None) ) for preset_name, preset in self._presets.items(): @@ -109,7 +107,7 @@ class LightPreset(SmartModule, LightPresetInterface): preset.brightness == brightness and ( 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.saturation == s @@ -124,7 +122,7 @@ class LightPreset(SmartModule, LightPresetInterface): """Set a light preset for the device.""" light = self._device.modules[SmartModule.Light] 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) else: preset = LightState(brightness=100)