4343
4444from roborock import SHORT_MODEL_TO_ENUM , RoborockCommand
4545from roborock .data import DeviceData , RoborockBase , UserData
46+ from roborock .data .b01_q10 .b01_q10_code_mappings import B01_Q10_DP
4647from roborock .device_features import DeviceFeatures
4748from roborock .devices .cache import Cache , CacheData
4849from roborock .devices .device import RoborockDevice
@@ -91,7 +92,12 @@ def wrapper(*args, **kwargs):
9192 context : RoborockContext = ctx .obj
9293
9394 async def run ():
94- return await func (* args , ** kwargs )
95+ try :
96+ await func (* args , ** kwargs )
97+ except Exception :
98+ _LOGGER .exception ("Uncaught exception in command" )
99+ click .echo (f"Error: { sys .exc_info ()[1 ]} " , err = True )
100+ await context .cleanup ()
95101
96102 if context .is_session_mode ():
97103 # Session mode - run in the persistent loop
@@ -739,6 +745,16 @@ async def network_info(ctx, device_id: str):
739745 await _display_v1_trait (context , device_id , lambda v1 : v1 .network_info )
740746
741747
748+ def _parse_b01_q10_command (cmd : str ) -> B01_Q10_DP | None :
749+ """Parse B01_Q10 command from either enum name or value."""
750+ for func in (B01_Q10_DP .from_code , B01_Q10_DP .from_name , B01_Q10_DP .from_value ):
751+ try :
752+ return func (cmd )
753+ except ValueError :
754+ continue
755+ return None
756+
757+
742758@click .command ()
743759@click .option ("--device_id" , required = True )
744760@click .option ("--cmd" , required = True )
@@ -749,12 +765,20 @@ async def command(ctx, cmd, device_id, params):
749765 context : RoborockContext = ctx .obj
750766 device_manager = await context .get_device_manager ()
751767 device = await device_manager .get_device (device_id )
752- if device .v1_properties is None :
753- raise RoborockException (f"Device { device .name } does not support V1 protocol" )
754- command_trait : Trait = device .v1_properties .command
755- result = await command_trait .send (cmd , json .loads (params ) if params is not None else None )
756- if result :
757- click .echo (dump_json (result ))
768+ if device .v1_properties is not None :
769+ command_trait : Trait = device .v1_properties .command
770+ result = await command_trait .send (cmd , json .loads (params ) if params is not None else {})
771+ if result :
772+ click .echo (dump_json (result ))
773+ elif device .b01_q10_properties is not None :
774+ # Parse B01_Q10_DP from either enum name or the value
775+ if (cmd_value := _parse_b01_q10_command (cmd )) is None :
776+ raise RoborockException (f"Invalid command { cmd } for B01_Q10 device" )
777+ await device .b01_q10_properties .send (cmd_value , json .loads (params ) if params is not None else {})
778+ # B10 Commands don't have a specific time to respond, so wait a bit
779+ await asyncio .sleep (5 )
780+ else :
781+ raise RoborockException (f"Device { device .name } does not support sending raw commands" )
758782
759783
760784@click .command ()
0 commit comments