mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
smartbulb: Limit brightness range to 1-100 (#829)
The allowed brightness for tested light devices (L530, L900) is [1-100] instead of [0-100] like it was for some kasa devices.
This commit is contained in:
@@ -28,8 +28,7 @@ class SmartBulb(SmartDevice, Bulb):
|
||||
@property
|
||||
def is_dimmable(self) -> bool:
|
||||
"""Whether the bulb supports brightness changes."""
|
||||
# TODO: this makes an assumption that only dimmables report this
|
||||
return "brightness" in self._info
|
||||
return "Brightness" in self.modules
|
||||
|
||||
@property
|
||||
def is_variable_color_temp(self) -> bool:
|
||||
@@ -188,6 +187,11 @@ class SmartBulb(SmartDevice, Bulb):
|
||||
|
||||
return await self.protocol.query({"set_device_info": {"color_temp": temp}})
|
||||
|
||||
def _raise_for_invalid_brightness(self, value: int):
|
||||
"""Raise error on invalid brightness value."""
|
||||
if not isinstance(value, int) or not (1 <= value <= 100):
|
||||
raise ValueError(f"Invalid brightness value: {value} (valid range: 1-100%)")
|
||||
|
||||
async def set_brightness(
|
||||
self, brightness: int, *, transition: Optional[int] = None
|
||||
) -> Dict:
|
||||
@@ -201,25 +205,12 @@ class SmartBulb(SmartDevice, Bulb):
|
||||
if not self.is_dimmable: # pragma: no cover
|
||||
raise KasaException("Bulb is not dimmable.")
|
||||
|
||||
self._raise_for_invalid_brightness(brightness)
|
||||
|
||||
return await self.protocol.query(
|
||||
{"set_device_info": {"brightness": brightness}}
|
||||
)
|
||||
|
||||
# Default state information, should be made to settings
|
||||
"""
|
||||
"info": {
|
||||
"default_states": {
|
||||
"re_power_type": "always_on",
|
||||
"type": "last_states",
|
||||
"state": {
|
||||
"brightness": 36,
|
||||
"hue": 0,
|
||||
"saturation": 0,
|
||||
"color_temp": 2700,
|
||||
},
|
||||
},
|
||||
"""
|
||||
|
||||
async def set_effect(
|
||||
self,
|
||||
effect: str,
|
||||
@@ -229,15 +220,6 @@ class SmartBulb(SmartDevice, Bulb):
|
||||
) -> None:
|
||||
"""Set an effect on the device."""
|
||||
raise NotImplementedError()
|
||||
# TODO: the code below does to activate the effect but gives no error
|
||||
return await self.protocol.query(
|
||||
{
|
||||
"set_device_info": {
|
||||
"dynamic_light_effect_enable": 1,
|
||||
"dynamic_light_effect_id": effect,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@property
|
||||
def presets(self) -> List[BulbPreset]:
|
||||
|
Reference in New Issue
Block a user