@@ -27,8 +27,7 @@ def is_color(self) -> bool:
27
27
@property
28
28
def is_dimmable (self ) -> bool :
29
29
"""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
32
31
33
32
@property
34
33
def is_variable_color_temp (self ) -> bool :
@@ -187,6 +186,13 @@ async def set_color_temp(
187
186
188
187
return await self .protocol .query ({"set_device_info" : {"color_temp" : temp }})
189
188
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
+
190
196
async def set_brightness (
191
197
self , brightness : int , * , transition : Optional [int ] = None
192
198
) -> Dict :
@@ -200,25 +206,12 @@ async def set_brightness(
200
206
if not self .is_dimmable : # pragma: no cover
201
207
raise KasaException ("Bulb is not dimmable." )
202
208
209
+ self ._raise_for_invalid_brightness (brightness )
210
+
203
211
return await self .protocol .query (
204
212
{"set_device_info" : {"brightness" : brightness }}
205
213
)
206
214
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
-
222
215
async def set_effect (
223
216
self ,
224
217
effect : str ,
@@ -228,15 +221,6 @@ async def set_effect(
228
221
) -> None :
229
222
"""Set an effect on the device."""
230
223
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
- )
240
224
241
225
@property
242
226
def presets (self ) -> List [BulbPreset ]:
0 commit comments