Commit c3ae98b
authored
fix: Fix operator precedence bug with walrus operator in cli.py command execution (#822)
## Description
There is a critical operator precedence bug in the `command` function inside `roborock/cli.py` affecting `B01_Q10` devices (and potentially others using the same logic).
Currently, the code reads:
`if cmd_value := B01_Q10_DP.from_any_optional(cmd) is None:`
Because the `is` operator binds tighter than the walrus operator (`:=`), Python evaluates `(B01_Q10_DP.from_any_optional(cmd) is None)` first.
If a valid command is passed, this evaluates to `False`, and the boolean `False` is assigned to `cmd_value`. The `if` block is then skipped, and `cmd_value` (`False`) is passed to `command_trait.send()`.
This results in a crash shortly after:
`AttributeError: 'bool' object has no attribute 'code'`
## Fix
Adding parentheses around the assignment expression fixes the evaluation order:
`if (cmd_value := B01_Q10_DP.from_any_optional(cmd)) is None:`1 parent 4ebb214 commit c3ae98b
1 file changed
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
780 | 780 | | |
781 | 781 | | |
782 | 782 | | |
783 | | - | |
| 783 | + | |
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
| |||
0 commit comments