forked from Python-roborock/python-roborock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_consumable.py
More file actions
90 lines (76 loc) · 3.28 KB
/
test_consumable.py
File metadata and controls
90 lines (76 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""Tests for the DoNotDisturbTrait class."""
from unittest.mock import AsyncMock, call
import pytest
from roborock.devices.device import RoborockDevice
from roborock.devices.traits.v1.consumeable import ConsumableAttribute, ConsumableTrait
from roborock.roborock_typing import RoborockCommand
CONSUMABLE_DATA = [
{
"main_brush_work_time": 879348,
"side_brush_work_time": 707618,
"filter_work_time": 738722,
"filter_element_work_time": 0,
"sensor_dirty_time": 455517,
}
]
@pytest.fixture
def consumable_trait(device: RoborockDevice) -> ConsumableTrait:
"""Create a ConsumableTrait instance with mocked dependencies."""
assert device.v1_properties
return device.v1_properties.consumables
async def test_get_consumable_data_success(consumable_trait: ConsumableTrait, mock_rpc_channel: AsyncMock) -> None:
"""Test successfully getting consumable data."""
# Setup mock to return the sample consumable data
mock_rpc_channel.send_command.return_value = CONSUMABLE_DATA
# Call the method
await consumable_trait.refresh()
# Verify the result
assert consumable_trait.main_brush_work_time == 879348
assert consumable_trait.side_brush_work_time == 707618
assert consumable_trait.filter_work_time == 738722
assert consumable_trait.filter_element_work_time == 0
assert consumable_trait.sensor_dirty_time == 455517
# Verify the RPC call was made correctly
mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_CONSUMABLE)
@pytest.mark.parametrize(
("consumable", "reset_param"),
[
(ConsumableAttribute.MAIN_BRUSH_WORK_TIME, "main_brush_work_time"),
(ConsumableAttribute.SIDE_BRUSH_WORK_TIME, "side_brush_work_time"),
(ConsumableAttribute.FILTER_WORK_TIME, "filter_work_time"),
(ConsumableAttribute.SENSOR_DIRTY_TIME, "sensor_dirty_time"),
(ConsumableAttribute.STRAINER_WORK_TIME, "strainer_work_time"),
(ConsumableAttribute.CLEANING_BRUSH_WORK_TIME, "cleaning_brush_work_time"),
],
)
async def test_reset_consumable_data(
consumable_trait: ConsumableTrait,
mock_rpc_channel: AsyncMock,
consumable: ConsumableAttribute,
reset_param: str,
) -> None:
"""Test successfully resetting consumable data."""
mock_rpc_channel.send_command.side_effect = [
{}, # Response for RESET_CONSUMABLE
# Response for GET_CONSUMABLE after reset
{
"main_brush_work_time": 5555,
"side_brush_work_time": 6666,
"filter_work_time": 7777,
"filter_element_work_time": 8888,
"sensor_dirty_time": 9999,
},
]
# Call the method
await consumable_trait.reset_consumable(consumable)
# Verify the RPC call was made correctly with expected parameters
assert mock_rpc_channel.send_command.mock_calls == [
call(RoborockCommand.RESET_CONSUMABLE, params=[reset_param]),
call(RoborockCommand.GET_CONSUMABLE),
]
# Verify the consumable data was refreshed correctly
assert consumable_trait.main_brush_work_time == 5555
assert consumable_trait.side_brush_work_time == 6666
assert consumable_trait.filter_work_time == 7777
assert consumable_trait.filter_element_work_time == 8888
assert consumable_trait.sensor_dirty_time == 9999