mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 18:54:08 +00:00
Fix iot light effect brightness (#1092)
Fixes issue where the brightness of the `iot` light effect is set properly on the light effect but read back incorrectly from the light.
This commit is contained in:
@@ -365,7 +365,7 @@ class IotBulb(IotDevice):
|
||||
|
||||
hue = light_state["hue"]
|
||||
saturation = light_state["saturation"]
|
||||
value = light_state["brightness"]
|
||||
value = self._brightness
|
||||
|
||||
return HSV(hue, saturation, value)
|
||||
|
||||
@@ -455,6 +455,13 @@ class IotBulb(IotDevice):
|
||||
if not self._is_dimmable: # pragma: no cover
|
||||
raise KasaException("Bulb is not dimmable.")
|
||||
|
||||
# If the device supports effects and one is active, we get the brightness
|
||||
# from the effect. This is not required when setting the brightness as
|
||||
# the device handles it via set_light_state
|
||||
if (
|
||||
light_effect := self.modules.get(Module.IotLightEffect)
|
||||
) is not None and light_effect.effect != light_effect.LIGHT_EFFECTS_OFF:
|
||||
return light_effect.brightness
|
||||
light_state = self.light_state
|
||||
return int(light_state["brightness"])
|
||||
|
||||
|
@@ -3,7 +3,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from ...interfaces.lighteffect import LightEffect as LightEffectInterface
|
||||
from ...module import Module
|
||||
from ..effects import EFFECT_MAPPING_V1, EFFECT_NAMES_V1
|
||||
from ..iotmodule import IotModule
|
||||
|
||||
@@ -29,6 +28,11 @@ class LightEffect(IotModule, LightEffectInterface):
|
||||
|
||||
return self.LIGHT_EFFECTS_OFF
|
||||
|
||||
@property
|
||||
def brightness(self) -> int:
|
||||
"""Return light effect brightness."""
|
||||
return self.data["lighting_effect_state"]["brightness"]
|
||||
|
||||
@property
|
||||
def effect_list(self) -> list[str]:
|
||||
"""Return built-in effects list.
|
||||
@@ -60,18 +64,21 @@ class LightEffect(IotModule, LightEffectInterface):
|
||||
:param int transition: The wanted transition time
|
||||
"""
|
||||
if effect == self.LIGHT_EFFECTS_OFF:
|
||||
light_module = self._device.modules[Module.Light]
|
||||
effect_off_state = light_module.state
|
||||
if brightness is not None:
|
||||
effect_off_state.brightness = brightness
|
||||
if transition is not None:
|
||||
effect_off_state.transition = transition
|
||||
await light_module.set_state(effect_off_state)
|
||||
if self.effect in EFFECT_MAPPING_V1:
|
||||
# TODO: We could query get_lighting_effect here to
|
||||
# get the custom effect although not sure how to find
|
||||
# custom effects
|
||||
effect_dict = EFFECT_MAPPING_V1[self.effect]
|
||||
else:
|
||||
effect_dict = EFFECT_MAPPING_V1["Aurora"]
|
||||
effect_dict = {**effect_dict}
|
||||
effect_dict["enable"] = 0
|
||||
await self.set_custom_effect(effect_dict)
|
||||
elif effect not in EFFECT_MAPPING_V1:
|
||||
raise ValueError(f"The effect {effect} is not a built in effect.")
|
||||
else:
|
||||
effect_dict = EFFECT_MAPPING_V1[effect]
|
||||
|
||||
effect_dict = {**effect_dict}
|
||||
if brightness is not None:
|
||||
effect_dict["brightness"] = brightness
|
||||
if transition is not None:
|
||||
|
Reference in New Issue
Block a user