Skip to content

Commit 35f7e8f

Browse files
committed
refactor: simplify B01_Q10 command parsing by removing a helper function and utilizing from_any_optional.
1 parent 9ee7f01 commit 35f7e8f

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

roborock/cli.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -764,21 +764,6 @@ async def network_info(ctx, device_id: str):
764764
await _display_v1_trait(context, device_id, lambda v1: v1.network_info)
765765

766766

767-
def _parse_b01_q10_command(cmd: str) -> B01_Q10_DP:
768-
"""Parse B01_Q10 command from either enum name or value."""
769-
try:
770-
return B01_Q10_DP(int(cmd))
771-
except ValueError:
772-
try:
773-
return B01_Q10_DP.from_name(cmd)
774-
except ValueError:
775-
try:
776-
return B01_Q10_DP.from_value(cmd)
777-
except ValueError:
778-
pass
779-
raise RoborockException(f"Invalid command {cmd} for B01_Q10 device")
780-
781-
782767
@click.command()
783768
@click.option("--device_id", required=True)
784769
@click.option("--cmd", required=True)
@@ -795,7 +780,8 @@ async def command(ctx, cmd, device_id, params):
795780
if result:
796781
click.echo(dump_json(result))
797782
elif device.b01_q10_properties is not None:
798-
cmd_value = _parse_b01_q10_command(cmd)
783+
if cmd_value := B01_Q10_DP.from_any_optional(cmd) is None:
784+
raise RoborockException(f"Invalid command {cmd} for B01_Q10 device")
799785
command_trait: Trait = device.b01_q10_properties.command
800786
await command_trait.send(cmd_value, json.loads(params) if params is not None else None)
801787
click.echo("Command sent successfully; Enable debug logging (-d) to see responses.")

0 commit comments

Comments
 (0)