@@ -438,6 +438,16 @@ async def _display_v1_trait(context: RoborockContext, device_id: str, display_fu
438438 click .echo (dump_json (trait .as_dict ()))
439439
440440
441+ async def _q10_vacuum_trait (context : RoborockContext , device_id : str ):
442+ """Get VacuumTrait from Q10 device."""
443+ device_manager = await context .get_device_manager ()
444+ device = await device_manager .get_device (device_id )
445+ trait = device .traits .get ("VacuumTrait" )
446+ if not trait :
447+ raise RoborockUnsupportedFeature ("Device does not have VacuumTrait. Is it a Q10?" )
448+ return trait
449+
450+
441451@session .command ()
442452@click .option ("--device_id" , required = True )
443453@click .pass_context
@@ -1148,11 +1158,7 @@ def write_markdown_table(product_features: dict[str, dict[str, any]], all_featur
11481158async def q10_vacuum_start (ctx , device_id ):
11491159 """Start vacuum cleaning on Q10 device."""
11501160 context : RoborockContext = ctx .obj
1151- device_manager = await context .get_device_manager ()
1152- device = await device_manager .get_device (device_id )
1153- trait = device .traits .get ("VacuumTrait" )
1154- if not trait :
1155- raise RoborockUnsupportedFeature ("Device does not have VacuumTrait. Is it a Q10?" )
1161+ trait = await _q10_vacuum_trait (context , device_id )
11561162 await trait .start_clean ()
11571163 click .echo ("Starting vacuum cleaning..." )
11581164
@@ -1164,11 +1170,7 @@ async def q10_vacuum_start(ctx, device_id):
11641170async def q10_vacuum_pause (ctx , device_id ):
11651171 """Pause vacuum cleaning on Q10 device."""
11661172 context : RoborockContext = ctx .obj
1167- device_manager = await context .get_device_manager ()
1168- device = await device_manager .get_device (device_id )
1169- trait = device .traits .get ("VacuumTrait" )
1170- if not trait :
1171- raise RoborockUnsupportedFeature ("Device does not have VacuumTrait. Is it a Q10?" )
1173+ trait = await _q10_vacuum_trait (context , device_id )
11721174 await trait .pause_clean ()
11731175 click .echo ("Pausing vacuum cleaning..." )
11741176
@@ -1180,11 +1182,7 @@ async def q10_vacuum_pause(ctx, device_id):
11801182async def q10_vacuum_resume (ctx , device_id ):
11811183 """Resume vacuum cleaning on Q10 device."""
11821184 context : RoborockContext = ctx .obj
1183- device_manager = await context .get_device_manager ()
1184- device = await device_manager .get_device (device_id )
1185- trait = device .traits .get ("VacuumTrait" )
1186- if not trait :
1187- raise RoborockUnsupportedFeature ("Device does not have VacuumTrait. Is it a Q10?" )
1185+ trait = await _q10_vacuum_trait (context , device_id )
11881186 await trait .resume_clean ()
11891187 click .echo ("Resuming vacuum cleaning..." )
11901188
@@ -1196,11 +1194,7 @@ async def q10_vacuum_resume(ctx, device_id):
11961194async def q10_vacuum_stop (ctx , device_id ):
11971195 """Stop vacuum cleaning on Q10 device."""
11981196 context : RoborockContext = ctx .obj
1199- device_manager = await context .get_device_manager ()
1200- device = await device_manager .get_device (device_id )
1201- trait = device .traits .get ("VacuumTrait" )
1202- if not trait :
1203- raise RoborockUnsupportedFeature ("Device does not have VacuumTrait. Is it a Q10?" )
1197+ trait = await _q10_vacuum_trait (context , device_id )
12041198 await trait .stop_clean ()
12051199 click .echo ("Stopping vacuum cleaning..." )
12061200
@@ -1212,11 +1206,7 @@ async def q10_vacuum_stop(ctx, device_id):
12121206async def q10_vacuum_dock (ctx , device_id ):
12131207 """Return vacuum to dock on Q10 device."""
12141208 context : RoborockContext = ctx .obj
1215- device_manager = await context .get_device_manager ()
1216- device = await device_manager .get_device (device_id )
1217- trait = device .traits .get ("VacuumTrait" )
1218- if not trait :
1219- raise RoborockUnsupportedFeature ("Device does not have VacuumTrait. Is it a Q10?" )
1209+ trait = await _q10_vacuum_trait (context , device_id )
12201210 await trait .return_to_dock ()
12211211 click .echo ("Returning vacuum to dock..." )
12221212
0 commit comments