|
| 1 | +"""Tests for the DoNotDisturbTrait class.""" |
| 2 | + |
| 3 | +from unittest.mock import AsyncMock |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from roborock.devices.device import RoborockDevice |
| 8 | +from roborock.devices.traits.v1.consumeable import ConsumableAttribute, ConsumableTrait |
| 9 | +from roborock.roborock_typing import RoborockCommand |
| 10 | + |
| 11 | +CONSUMABLE_DATA = [ |
| 12 | + { |
| 13 | + "main_brush_work_time": 879348, |
| 14 | + "side_brush_work_time": 707618, |
| 15 | + "filter_work_time": 738722, |
| 16 | + "filter_element_work_time": 0, |
| 17 | + "sensor_dirty_time": 455517, |
| 18 | + } |
| 19 | +] |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture |
| 23 | +def consumable_trait(device: RoborockDevice) -> ConsumableTrait: |
| 24 | + """Create a ConsumableTrait instance with mocked dependencies.""" |
| 25 | + assert device.v1_properties |
| 26 | + return device.v1_properties.consumables |
| 27 | + |
| 28 | + |
| 29 | +async def test_get_consumable_data_success(consumable_trait: ConsumableTrait, mock_rpc_channel: AsyncMock) -> None: |
| 30 | + """Test successfully getting consumable data.""" |
| 31 | + # Setup mock to return the sample consumable data |
| 32 | + mock_rpc_channel.send_command.return_value = CONSUMABLE_DATA |
| 33 | + |
| 34 | + # Call the method |
| 35 | + await consumable_trait.refresh() |
| 36 | + # Verify the result |
| 37 | + assert consumable_trait.main_brush_work_time == 879348 |
| 38 | + assert consumable_trait.side_brush_work_time == 707618 |
| 39 | + assert consumable_trait.filter_work_time == 738722 |
| 40 | + assert consumable_trait.filter_element_work_time == 0 |
| 41 | + assert consumable_trait.sensor_dirty_time == 455517 |
| 42 | + |
| 43 | + # Verify the RPC call was made correctly |
| 44 | + mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_CONSUMABLE) |
| 45 | + |
| 46 | + |
| 47 | +@pytest.mark.parametrize( |
| 48 | + ("consumable", "reset_param"), |
| 49 | + [ |
| 50 | + (ConsumableAttribute.MAIN_BRUSH_WORK_TIME, "main_brush_work_time"), |
| 51 | + (ConsumableAttribute.SIDE_BRUSH_WORK_TIME, "side_brush_work_time"), |
| 52 | + (ConsumableAttribute.FILTER_WORK_TIME, "filter_work_time"), |
| 53 | + (ConsumableAttribute.SENSOR_DIRTY_TIME, "sensor_dirty_time"), |
| 54 | + ], |
| 55 | +) |
| 56 | +async def test_reset_consumable_data( |
| 57 | + consumable_trait: ConsumableTrait, |
| 58 | + mock_rpc_channel: AsyncMock, |
| 59 | + consumable: ConsumableAttribute, |
| 60 | + reset_param: str, |
| 61 | +) -> None: |
| 62 | + """Test successfully resetting consumable data.""" |
| 63 | + # Call the method |
| 64 | + await consumable_trait.reset_consumable(consumable) |
| 65 | + |
| 66 | + # Verify the RPC call was made correctly with expected parameters |
| 67 | + mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.RESET_CONSUMABLE, params=[reset_param]) |
| 68 | + |
| 69 | + |
| 70 | +# |
0 commit comments