|
1 | 1 | """Tests for the pure V1 cleaning mode helpers.""" |
2 | 2 |
|
| 3 | +import itertools |
| 4 | + |
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | from roborock.data.v1.v1_clean_modes import ( |
|
13 | 15 | get_clean_modes, |
14 | 16 | get_clean_routes, |
15 | 17 | get_cleaning_mode_codes, |
| 18 | + get_cleaning_mode_options, |
16 | 19 | get_display_options, |
17 | 20 | get_motor_mode_commands, |
| 21 | + get_reported_special_mode, |
18 | 22 | get_setting_change_codes, |
| 23 | + get_supported_settings, |
19 | 24 | get_water_modes, |
20 | 25 | ) |
21 | 26 | from roborock.device_features import DeviceFeatures |
@@ -551,3 +556,108 @@ def test_fan_speed_display_options_keep_full_list_without_a_mop() -> None: |
551 | 556 | options = get_clean_modes(features) |
552 | 557 | assert VacuumModes.MAX_PLUS in options |
553 | 558 | assert get_display_options(CleaningSetting.FAN_SPEED, None, features, options) == options |
| 559 | + |
| 560 | + |
| 561 | +_FAN = CleaningSetting.FAN_SPEED |
| 562 | +_WATER = CleaningSetting.WATER_MODE |
| 563 | +_ROUTE = CleaningSetting.MOP_ROUTE |
| 564 | + |
| 565 | + |
| 566 | +@pytest.mark.parametrize( |
| 567 | + ("overrides", "expected"), |
| 568 | + [ |
| 569 | + # Vacuum-only: no mop module, so only the fan speed. |
| 570 | + ({"is_support_water_mode": False}, frozenset({_FAN})), |
| 571 | + # Saros-like: shake module with fast route, mop-only tab and water slide. |
| 572 | + ( |
| 573 | + {"is_pure_clean_mop_supported": True, "is_water_slide_mode_supported": True}, |
| 574 | + frozenset({_FAN, _WATER, _ROUTE}), |
| 575 | + ), |
| 576 | + # Shake module without fast route but with a mop-only tab: the route exists in mop mode. |
| 577 | + ( |
| 578 | + {"is_pure_clean_mop_supported": True, "is_clean_route_fast_mode_supported": False}, |
| 579 | + frozenset({_FAN, _WATER, _ROUTE}), |
| 580 | + ), |
| 581 | + # Shake module without mop-only tab and without fast route: the route is never adjustable. |
| 582 | + ( |
| 583 | + {"is_pure_clean_mop_supported": False, "is_clean_route_fast_mode_supported": False}, |
| 584 | + frozenset({_FAN, _WATER}), |
| 585 | + ), |
| 586 | + # Spin or roller mop: route setting without the shake module. |
| 587 | + ({"is_shake_mop_set_supported": False, "is_pure_clean_mop_supported": True}, frozenset({_FAN, _WATER})), |
| 588 | + ({"is_shake_mop_set_supported": False}, frozenset({_FAN, _WATER})), |
| 589 | + # Clean efficiency only changes the route values. |
| 590 | + ( |
| 591 | + {"is_pure_clean_mop_supported": True, "is_clean_efficiency_supported": True}, |
| 592 | + frozenset({_FAN, _WATER, _ROUTE}), |
| 593 | + ), |
| 594 | + # Max+ without a mop-only tab only changes the route values. |
| 595 | + ({"is_none_pure_clean_mop_with_max_plus": True}, frozenset({_FAN, _WATER, _ROUTE})), |
| 596 | + ], |
| 597 | +) |
| 598 | +def test_get_supported_settings(overrides: dict[str, bool], expected: frozenset[CleaningSetting]) -> None: |
| 599 | + assert get_supported_settings(_features(**overrides)) == expected |
| 600 | + |
| 601 | + |
| 602 | +_GRID_FLAGS = ( |
| 603 | + "is_shake_mop_set_supported", |
| 604 | + "is_clean_route_fast_mode_supported", |
| 605 | + "is_pure_clean_mop_supported", |
| 606 | + "is_support_water_mode", |
| 607 | + "is_clean_route_setting_supported", |
| 608 | + "is_clean_efficiency_supported", |
| 609 | + "is_none_pure_clean_mop_with_max_plus", |
| 610 | +) |
| 611 | + |
| 612 | + |
| 613 | +@pytest.mark.parametrize("values", list(itertools.product((False, True), repeat=len(_GRID_FLAGS)))) |
| 614 | +def test_supported_settings_match_adjustable_settings(values: tuple[bool, ...]) -> None: |
| 615 | + """A setting is supported exactly when it can be adjusted in at least one reachable cleaning mode.""" |
| 616 | + features = _features(**dict(zip(_GRID_FLAGS, values, strict=True))) |
| 617 | + reachable: list[CleaningMode | None] = [ |
| 618 | + mode |
| 619 | + for mode in get_cleaning_mode_options(features) |
| 620 | + if mode not in (CleaningMode.SMART_MODE, CleaningMode.CUSTOM) |
| 621 | + ] or [None] |
| 622 | + adjustable_somewhere: set[CleaningSetting] = set() |
| 623 | + for mode in reachable: |
| 624 | + adjustable_somewhere |= get_adjustable_settings(mode, features) |
| 625 | + assert get_supported_settings(features) == adjustable_somewhere |
| 626 | + |
| 627 | + |
| 628 | +@pytest.mark.parametrize( |
| 629 | + ("fan", "water", "route", "expected"), |
| 630 | + [ |
| 631 | + # Custom wins over SmartPlan when both are reported. |
| 632 | + (106, 202, 300, CleaningMode.CUSTOM), |
| 633 | + (102, 204, 300, CleaningMode.CUSTOM), |
| 634 | + (102, 202, 302, CleaningMode.CUSTOM), |
| 635 | + (106, 209, 300, CleaningMode.CUSTOM), |
| 636 | + (110, 202, 300, CleaningMode.SMART_MODE), |
| 637 | + (102, 209, 300, CleaningMode.SMART_MODE), |
| 638 | + (102, 202, 306, CleaningMode.SMART_MODE), |
| 639 | + # Regular codes, including a water slide position and the fast route, are not special. |
| 640 | + (102, 202, 300, None), |
| 641 | + (102, 235, 304, None), |
| 642 | + ], |
| 643 | +) |
| 644 | +def test_get_reported_special_mode(fan: int, water: int, route: int, expected: CleaningMode | None) -> None: |
| 645 | + features = _features(is_pure_clean_mop_supported=True) |
| 646 | + assert get_reported_special_mode(fan, water, route, features) == expected |
| 647 | + |
| 648 | + |
| 649 | +@pytest.mark.parametrize( |
| 650 | + ("fan", "water", "route", "expected"), |
| 651 | + [ |
| 652 | + # Without a mop only the fan power is read, so water and route codes do not count. |
| 653 | + (102, 204, 300, None), |
| 654 | + (102, 209, 306, None), |
| 655 | + (110, 204, 302, CleaningMode.SMART_MODE), |
| 656 | + (106, 209, 306, CleaningMode.CUSTOM), |
| 657 | + ], |
| 658 | +) |
| 659 | +def test_get_reported_special_mode_ignores_water_and_route_without_mop( |
| 660 | + fan: int, water: int, route: int, expected: CleaningMode | None |
| 661 | +) -> None: |
| 662 | + features = _features(is_support_water_mode=False) |
| 663 | + assert get_reported_special_mode(fan, water, route, features) == expected |
0 commit comments