|
| 1 | +from unittest import TestCase |
| 2 | +import pytest |
| 3 | +from .dummies import DummyDevice |
| 4 | +import datetime |
| 5 | +from miio import Vacuum, VacuumStatus, VacuumException |
| 6 | + |
| 7 | + |
| 8 | +class DummyVacuum(DummyDevice, Vacuum): |
| 9 | + STATE_CHARGING = 8 |
| 10 | + STATE_CLEANING = 5 |
| 11 | + STATE_IDLE = 3 |
| 12 | + STATE_HOME = 6 |
| 13 | + STATE_SPOT = 11 |
| 14 | + STATE_ERROR = 12 |
| 15 | + STATE_PAUSED = 10 |
| 16 | + STATE_MANUAL = 7 |
| 17 | + def __init__(self, *args, **kwargs): |
| 18 | + self.state = { |
| 19 | + 'state': 8, |
| 20 | + 'dnd_enabled': 1, |
| 21 | + 'clean_time': 0, |
| 22 | + 'msg_ver': 4, |
| 23 | + 'map_present': 1, |
| 24 | + 'error_code': 0, |
| 25 | + 'in_cleaning': 0, |
| 26 | + 'clean_area': 0, |
| 27 | + 'battery': 100, |
| 28 | + 'fan_power': 20, |
| 29 | + 'msg_seq': 320 |
| 30 | + } |
| 31 | + |
| 32 | + self.return_values = { |
| 33 | + 'get_status': self.vacuum_state, |
| 34 | + 'app_start': lambda x: self.change_mode("start"), |
| 35 | + 'app_stop': lambda x: self.change_mode("stop"), |
| 36 | + 'app_pause': lambda x: self.change_mode("home"), |
| 37 | + 'app_spot': lambda x: self.change_mode("spot"), |
| 38 | + 'app_charge': lambda x: self.change_mode("charge") |
| 39 | + } |
| 40 | + |
| 41 | + super().__init__(args, kwargs) |
| 42 | + |
| 43 | + def change_mode(self, new_mode): |
| 44 | + if new_mode == "spot": |
| 45 | + self.state["state"] = DummyVacuum.STATE_SPOT |
| 46 | + elif new_mode == "home": |
| 47 | + self.state["state"] = DummyVacuum.STATE_HOME |
| 48 | + elif new_mode == "start": |
| 49 | + self.state["state"] = DummyVacuum.STATE_CLEANING |
| 50 | + elif new_mode == "stop": |
| 51 | + self.state["state"] = DummyVacuum.STATE_IDLE |
| 52 | + elif new_mode == "charge": |
| 53 | + self.state["state"] = DummyVacuum.STATE_CHARGING |
| 54 | + |
| 55 | + def vacuum_state(self, _): |
| 56 | + return [self.state] |
| 57 | + |
| 58 | + |
| 59 | +@pytest.fixture(scope="class") |
| 60 | +def dummyvacuum(request): |
| 61 | + request.cls.device = DummyVacuum() |
| 62 | + # TODO add ability to test on a real device |
| 63 | + |
| 64 | + |
| 65 | +@pytest.mark.usefixtures("dummyvacuum") |
| 66 | +class TestVacuum(TestCase): |
| 67 | + def status(self): |
| 68 | + return self.device.status() |
| 69 | + |
| 70 | + def test_status(self): |
| 71 | + self.device._reset_state() |
| 72 | + status = self.status() |
| 73 | + assert status.is_on is False |
| 74 | + assert status.dnd is True |
| 75 | + assert status.clean_time == datetime.timedelta() |
| 76 | + assert status.error_code == 0 |
| 77 | + assert status.error == "No error" |
| 78 | + assert status.fanspeed == self.device.start_state["fan_power"] |
| 79 | + assert status.battery == self.device.start_state["battery"] |
| 80 | + |
| 81 | + def test_status_with_errors(self): |
| 82 | + errors = {5: "Clean main brush", |
| 83 | + 19: "Unpowered charging station"} |
| 84 | + |
| 85 | + for errcode, error in errors.items(): |
| 86 | + self.device.state["state"] = self.device.STATE_ERROR |
| 87 | + self.device.state["error_code"] = errcode |
| 88 | + assert self.status().is_on is False |
| 89 | + assert self.status().got_error is True |
| 90 | + assert self.status().error_code == errcode |
| 91 | + assert self.status().error == error |
| 92 | + |
| 93 | + def test_start_and_stop(self): |
| 94 | + assert self.status().is_on is False |
| 95 | + self.device.start() |
| 96 | + assert self.status().is_on is True |
| 97 | + assert self.status().state_code == self.device.STATE_CLEANING |
| 98 | + self.device.stop() |
| 99 | + assert self.status().is_on is False |
| 100 | + |
| 101 | + def test_spot(self): |
| 102 | + assert self.status().is_on is False |
| 103 | + self.device.spot() |
| 104 | + assert self.status().is_on is True |
| 105 | + assert self.status().state_code == self.device.STATE_SPOT |
| 106 | + self.device.stop() |
| 107 | + assert self.status().is_on is False |
| 108 | + |
| 109 | + def test_pause(self): |
| 110 | + self.device.start() |
| 111 | + assert self.status().is_on is True |
| 112 | + self.device.pause() |
| 113 | + assert self.status().state_code == self.device.STATE_PAUSED |
| 114 | + |
| 115 | + def test_home(self): |
| 116 | + self.device.start() |
| 117 | + assert self.status().is_on is True |
| 118 | + self.device.home() |
| 119 | + assert self.status().state_code == self.device.STATE_HOME |
| 120 | + self.device.change_mode(self.device.STATE_CHARGING) |
| 121 | + |
| 122 | + def test_manual_control(self): |
| 123 | + self.fail() |
| 124 | + |
| 125 | + @pytest.mark.skip("unknown handling") |
| 126 | + def test_log_upload(self): |
| 127 | + self.fail() |
| 128 | + |
| 129 | + def test_consumable_status(self): |
| 130 | + self.fail() |
| 131 | + |
| 132 | + @pytest.mark.skip("consumable reset is not implemented") |
| 133 | + def test_consumable_reset(self): |
| 134 | + self.fail() |
| 135 | + |
| 136 | + def test_map(self): |
| 137 | + self.fail() |
| 138 | + |
| 139 | + def test_clean_history(self): |
| 140 | + self.fail() |
| 141 | + |
| 142 | + def test_clean_details(self): |
| 143 | + self.fail() |
| 144 | + |
| 145 | + def test_find(self): |
| 146 | + self.fail() |
| 147 | + |
| 148 | + def test_timer(self): |
| 149 | + self.fail() |
| 150 | + |
| 151 | + def test_dnd(self): |
| 152 | + self.fail() |
| 153 | + |
| 154 | + def test_fan_speed(self): |
| 155 | + self.fail() |
| 156 | + |
| 157 | + def test_sound_info(self): |
| 158 | + self.fail() |
| 159 | + |
| 160 | + def test_serial_number(self): |
| 161 | + self.fail() |
| 162 | + |
| 163 | + def test_timezone(self): |
| 164 | + self.fail() |
| 165 | + |
| 166 | + def test_raw_command(self): |
| 167 | + self.fail() |
0 commit comments