8000 smartbulb: Limit brightness range to 1-100 · python-kasa/python-kasa@2530204 · GitHub
[go: up one dir, main page]

Skip to conten 8000 t

Commit 2530204

Browse files
committed
smartbulb: Limit brightness range to 1-100
1 parent 9b69516 commit 2530204

File tree

1 file changed

+10
-26
lines changed

1 file changed

+10
-26
lines changed

kasa/smart/smartbulb.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def is_color(self) -> bool:
2727
@property
2828
def is_dimmable(self) -> bool:
2929
"""Whether the bulb supports brightness changes."""
30-
# TODO: this makes an assumption that only dimmables report this
31-
return "brightness" in self._info
30+
return "Brightness" in self.modules
3231

3332
@property
3433
def is_variable_color_temp(self) -> bool:
@@ -187,6 +186,13 @@ async def set_color_temp(
187186

188187
return await self.protocol.query({"set_device_info": {"color_temp": temp}})
189188

189+
190+
def _raise_for_invalid_brightness(self, value: int):
191+
"""Raise error on invalid brightness value."""
192+
if not isinstance(value, int) or not (0 < value <= 100):
193+
raise ValueError(f"Invalid brightness value: {value} (valid range: 1-100%)")
194+
195+
190196
async def set_brightness(
191197
self, brightness: int, *, transition: Optional[int] = None
192198
) -> Dict:
@@ -200,25 +206,12 @@ async def set_brightness(
200206
if not self.is_dimmable: # pragma: no cover
201207
raise KasaException("Bulb is not dimmable.")
202208

209+
self._raise_for_invalid_brightness(brightness)
210+
203211
return await self.protocol.query(
204212
{"set_device_info": {"brightness": brightness}}
205213
)
206214

207-
# Default state information, should be made to settings
208-
"""
209-
"info": {
210-
"default_states": {
211-
"re_power_type": "always_on",
212-
"type": "last_states",
213-
"state": {
214-
"brightness": 36,
215-
"hue": 0,
216-
"saturation": 0,
217-
"color_temp": 2700,
218-
},
219-
},
220-
"""
221-
222215
async def set_effect(
223216
self,
224217
effect: str,
@@ -228,15 +221,6 @@ async def set_effect(
228221
) -> None:
229222
"""Set an effect on the device."""
230223
raise NotImplementedError()
231-
# TODO: the code below does to activate the effect but gives no error
232-
return await self.protocol.query(
233-
{
234-
"set_device_info": {
235-
"dynamic_light_effect_enable": 1,
236-
"dynamic_light_effect_id": effect,
237-
}
238-
}
239-
)
240224

241225
@property
242226
def presets(self) -> List[BulbPreset]:

0 commit comments

Comments
 (0)
0