mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-11-23 15:11:25 +00:00
Merge remote-tracking branch 'upstream/master' into feat/light_module_feats
This commit is contained in:
@@ -207,17 +207,18 @@ class Light(IotModule, LightInterface):
|
||||
return self._light_state
|
||||
|
||||
async def _post_update_hook(self) -> None:
|
||||
if self._device.is_on is False:
|
||||
device = self._device
|
||||
if device.is_on is False:
|
||||
state = LightState(light_on=False)
|
||||
else:
|
||||
state = LightState(light_on=True)
|
||||
if self._device._is_dimmable:
|
||||
if device._is_dimmable:
|
||||
state.brightness = self.brightness
|
||||
if self._device._is_color:
|
||||
if device._is_color:
|
||||
hsv = self.hsv
|
||||
state.hue = hsv.hue
|
||||
state.saturation = hsv.saturation
|
||||
if self._device._is_variable_color_temp:
|
||||
if device._is_variable_color_temp:
|
||||
state.color_temp = self.color_temp
|
||||
self._light_state = state
|
||||
|
||||
|
||||
@@ -85,17 +85,19 @@ class LightPreset(IotModule, LightPresetInterface):
|
||||
def preset(self) -> str:
|
||||
"""Return current preset name."""
|
||||
light = self._device.modules[Module.Light]
|
||||
is_color = light.has_feature("hsv")
|
||||
is_variable_color_temp = light.has_feature("color_temp")
|
||||
|
||||
brightness = light.brightness
|
||||
color_temp = light.color_temp if light.is_variable_color_temp else None
|
||||
h, s = (light.hsv.hue, light.hsv.saturation) if light.is_color else (None, None)
|
||||
color_temp = light.color_temp if is_variable_color_temp else None
|
||||
|
||||
h, s = (light.hsv.hue, light.hsv.saturation) if is_color else (None, None)
|
||||
for preset_name, preset in self._presets.items():
|
||||
if (
|
||||
preset.brightness == brightness
|
||||
and (
|
||||
preset.color_temp == color_temp or not light.is_variable_color_temp
|
||||
)
|
||||
and (preset.hue == h or not light.is_color)
|
||||
and (preset.saturation == s or not light.is_color)
|
||||
and (preset.color_temp == color_temp or not is_variable_color_temp)
|
||||
and (preset.hue == h or not is_color)
|
||||
and (preset.saturation == s or not is_color)
|
||||
):
|
||||
return preset_name
|
||||
return self.PRESET_NOT_SET
|
||||
@@ -107,7 +109,7 @@ class LightPreset(IotModule, LightPresetInterface):
|
||||
"""Set a light preset for the device."""
|
||||
light = self._device.modules[Module.Light]
|
||||
if preset_name == self.PRESET_NOT_SET:
|
||||
if light.is_color:
|
||||
if light.has_feature("hsv"):
|
||||
preset = LightState(hue=0, saturation=0, brightness=100)
|
||||
else:
|
||||
preset = LightState(brightness=100)
|
||||
|
||||
Reference in New Issue
Block a user