1
- from typing import Dict , Set
1
+ from typing import Dict , List , Set
2
2
3
3
import pytest
4
4
5
5
from kasa import (
6
6
Credentials ,
7
7
Device ,
8
+ DeviceType ,
8
9
Discover ,
9
10
)
10
11
from kasa .iot import IotBulb , IotDimmer , IotLightStrip , IotPlug , IotStrip , IotWallSwitch
127
128
IP_MODEL_CACHE : Dict [str , str ] = {}
128
129
129
130
131
+ def parametrize_combine (parametrized : List [pytest .MarkDecorator ]):
132
+ """Combine multiple pytest parametrize dev marks into one set of fixtures."""
133
+ fixtures = set ()
134
+ for param in parametrized :
135
+ if param .args [0 ] != "dev" :
136
+ raise Exception (f"Supplied mark is not for dev fixture: { param .args [0 ]} " )
137
+ fixtures .update (param .args [1 ])
138
+ return pytest .mark .parametrize (
139
+ "dev" ,
140
+ sorted (list (fixtures )),
141
+ indirect = True ,
142
+ ids = idgenerator ,
143
+ )
144
+
145
+
130
146
def parametrize (
131
147
desc ,
132
148
* ,
133
149
model_filter = None ,
134
150
protocol_filter = None ,
135
151
component_filter = None ,
136
152
data_root_filter = None ,
153
+ device_type_filter = None ,
137
154
ids = None ,
138
155
):
139
156
if ids is None :
@@ -146,6 +163,7 @@ def parametrize(
146
163
protocol_filter = protocol_filter ,
147
164
component_filter = component_filter ,
148
165
data_root_filter = data_root_filter ,
166
+ device_type_filter = device_type_filter ,
149
167
),
150
168
indirect = True ,
151
169
ids = ids ,
@@ -169,7 +187,6 @@ def parametrize(
169
187
protocol_filter = {"IOT" },
170
188
)
171
189
172
- bulb = parametrize ("bulbs" , model_filter = BULBS , protocol_filter = {"SMART" , "IOT" })
173
190
plug = parametrize ("plugs" , model_filter = PLUGS , protocol_filter = {"IOT" , "SMART" })
174
191
plug_iot = parametrize ("plugs iot" , model_filter = PLUGS , protocol_filter = {"IOT" })
175
192
wallswitch = parametrize (
@@ -216,9 +233,16 @@ def parametrize(
216
233
model_filter = BULBS_IOT_VARIABLE_TEMP ,
217
234
protocol_filter = {"IOT" },
218
235
)
236
+
237
+ bulb_smart = parametrize (
238
+ "bulb devices smart" ,
239
+ device_type_filter = [DeviceType .Bulb , DeviceType .LightStrip ],
240
+ protocol_filter = {"SMART" },
241
+ )
219
242
bulb_iot = parametrize (
220
243
"bulb devices iot" , model_filter = BULBS_IOT , protocol_filter = {"IOT" }
221
244
)
245
+ bulb = parametrize_combine ([bulb_smart , bulb_iot ])
222
246
223
247
strip_iot = parametrize (
224
248
"strip devices iot" , model_filter = STRIPS_IOT , protocol_filter = {"IOT" }
@@ -233,9 +257,6 @@ def parametrize(
233
257
switch_smart = parametrize (
234
258
"switch devices smart" , model_filter = SWITCHES_SMART , protocol_filter = {"SMART" }
235
259
)
236
- bulb_smart = parametrize (
237
- "bulb devices smart" , model_filter = BULBS_SMART , protocol_filter = {"SMART" }
238
- )
239
260
dimmers_smart = parametrize (
240
261
"dimmer devices smart" , model_filter = DIMMERS_SMART , protocol_filter = {"SMART" }
241
262
)
0 commit comments