@@ -257,20 +257,27 @@ def _mocked_device(
257
257
for module_name in modules
258
258
}
259
259
260
+ device_features = {}
260
261
if features :
261
- device . features = {
262
+ device_features = {
262
263
feature_id : _mocked_feature (feature_id , require_fixture = True )
263
264
for feature_id in features
264
265
if isinstance (feature_id , str )
265
266
}
266
267
267
- device . features .update (
268
+ device_features .update (
268
269
{
269
270
feature .id : feature
270
271
for feature in features
271
272
if isinstance (feature , Feature )
272
273
}
273
274
)
275
+ device .features = device_features
276
+
277
+ for mod in device .modules .values ():
278
+ mod .get_feature .side_effect = device_features .get
279
+ mod .has_feature .side_effect = lambda id : id in device_features
280
+
274
281
device .children = []
275
282
if children :
276
283
for child in children :
@@ -289,6 +296,7 @@ def _mocked_device(
289
296
device .protocol = _mock_protocol ()
290
297
device .config = device_config
291
298
device .credentials_hash = credentials_hash
299
+
292
300
return device
293
301
294
302
@@ -303,8 +311,8 @@ def _mocked_feature(
303
311
precision_hint = None ,
304
312
choices = None ,
305
313
unit = None ,
306
- minimum_value = 0 ,
307
- maximum_value = 2 ** 16 , # Arbitrary max
314
+ minimum_value = None ,
315
+ maximum_value = None ,
308
316
) -> Feature :
309
317
"""Get a mocked feature.
310
318
@@ -334,11 +342,14 @@ def _mocked_feature(
334
342
feature .unit = unit or fixture .get ("unit" )
335
343
336
344
# number
337
- feature .minimum_value = minimum_value or fixture .get ("minimum_value" )
338
- feature .maximum_value = maximum_value or fixture .get ("maximum_value" )
345
+ min_val = minimum_value or fixture .get ("minimum_value" )
346
+ feature .minimum_value = 0 if min_val is None else min_val
347
+ max_val = maximum_value or fixture .get ("maximum_value" )
348
+ feature .maximum_value = 2 ** 16 if max_val is None else max_val
339
349
340
350
# select
341
351
feature .choices = choices or fixture .get ("choices" )
352
+
342
353
return feature
343
354
344
355
@@ -350,13 +361,7 @@ def _mocked_light_module(device) -> Light:
350
361
light .state = LightState (
351
362
light_on = True , brightness = light .brightness , color_temp = light .color_temp
352
363
)
353
- light .is_color = True
354
- light .is_variable_color_temp = True
355
- light .is_dimmable = True
356
- light .is_brightness = True
357
- light .has_effects = False
358
364
light .hsv = (10 , 30 , 5 )
359
- light .valid_temperature_range = ColorTempRange (min = 4000 , max = 9000 )
360
365
light .hw_info = {"sw_ver" : "1.0.0" , "hw_ver" : "1.0.0" }
361
366
362
367
async def _set_state (state , * _ , ** __ ):
@@ -389,7 +394,6 @@ async def _set_color_temp(temp, *_, **__):
389
394
390
395
def _mocked_light_effect_module (device ) -> LightEffect :
391
396
effect = MagicMock (spec = LightEffect , name = "Mocked light effect" )
392
- effect .has_effects = True
393
397
effect .has_custom_effects = True
394
398
effect .effect = "Effect1"
395
399
effect .effect_list = ["Off" , "Effect1" , "Effect2" ]
0 commit comments