|
13 | 13 | from deebot_client.commands.xml import GetBatteryInfo |
14 | 14 | from deebot_client.const import DataType |
15 | 15 | from deebot_client.device import Device |
16 | | -from deebot_client.events import AvailabilityEvent |
| 16 | +from deebot_client.events import AvailabilityEvent, StateEvent |
| 17 | +from deebot_client.events.map import Position, PositionsEvent |
17 | 18 | from deebot_client.events.network import NetworkInfoEvent |
18 | 19 | from deebot_client.hardware import get_static_device_info |
19 | 20 | from deebot_client.messages.json import OnBattery |
20 | 21 | from deebot_client.messages.xml import BatteryInfo |
21 | 22 | from deebot_client.models import DeviceInfo, StaticDeviceInfo |
22 | 23 | from deebot_client.mqtt_client import MqttClient, SubscriberInfo |
| 24 | +from deebot_client.rs.map import PositionType |
23 | 25 | from tests.helpers import mock_static_device_info |
24 | 26 | from tests.helpers.tasks import block_till_done |
25 | 27 |
|
26 | 28 | if TYPE_CHECKING: |
27 | 29 | from deebot_client.authentication import Authenticator |
| 30 | + from deebot_client.event_bus import EventBus |
28 | 31 | from deebot_client.message import Message |
29 | 32 | from deebot_client.models import ApiDeviceInfo |
30 | 33 |
|
@@ -277,3 +280,85 @@ async def on_status(event: AvailabilityEvent) -> None: |
277 | 280 |
|
278 | 281 | # teardown bot |
279 | 282 | await bot.teardown() |
| 283 | + |
| 284 | + |
| 285 | +@pytest.mark.parametrize( |
| 286 | + ("pos_event", "expected_call"), |
| 287 | + [ |
| 288 | + (PositionsEvent([]), False), |
| 289 | + (PositionsEvent([Position(PositionType.CHARGER, 0, 0, 0)]), False), |
| 290 | + (PositionsEvent([Position(PositionType.DEEBOT, 0, 0, 0)]), False), |
| 291 | + ( |
| 292 | + PositionsEvent( |
| 293 | + [ |
| 294 | + Position(PositionType.DEEBOT, 0, 0, 0), |
| 295 | + Position(PositionType.CHARGER, 0, 0, 0), |
| 296 | + ] |
| 297 | + ), |
| 298 | + True, |
| 299 | + ), |
| 300 | + ( |
| 301 | + PositionsEvent( |
| 302 | + [ |
| 303 | + Position(PositionType.CHARGER, 0, 0, 0), |
| 304 | + Position(PositionType.DEEBOT, 0, 0, 0), |
| 305 | + ] |
| 306 | + ), |
| 307 | + True, |
| 308 | + ), |
| 309 | + ( |
| 310 | + PositionsEvent( |
| 311 | + [ |
| 312 | + Position(PositionType.CHARGER, 1, 0, 0), |
| 313 | + Position(PositionType.DEEBOT, 0, 0, 0), |
| 314 | + ] |
| 315 | + ), |
| 316 | + False, |
| 317 | + ), |
| 318 | + ( |
| 319 | + PositionsEvent( |
| 320 | + [ |
| 321 | + Position(PositionType.DEEBOT, 0, 0, 0), |
| 322 | + Position(PositionType.CHARGER, 1, 0, 0), |
| 323 | + ] |
| 324 | + ), |
| 325 | + False, |
| 326 | + ), |
| 327 | + ( |
| 328 | + PositionsEvent( |
| 329 | + [ |
| 330 | + Position(PositionType.DEEBOT, 0, 0, 0), |
| 331 | + Position(PositionType.CHARGER, 1, 0, 0), |
| 332 | + Position(PositionType.CHARGER, 0, 0, 0), |
| 333 | + ] |
| 334 | + ), |
| 335 | + True, |
| 336 | + ), |
| 337 | + ], |
| 338 | +) |
| 339 | +async def test_onPos_device_handling( |
| 340 | + authenticator: Authenticator, |
| 341 | + device_info: DeviceInfo, |
| 342 | + event_bus_mock: Mock, |
| 343 | + event_bus: EventBus, |
| 344 | + pos_event: PositionsEvent, |
| 345 | + expected_call: bool, |
| 346 | +) -> None: |
| 347 | + """Test the available check including if the status Event is fired correctly.""" |
| 348 | + with patch("deebot_client.device.EventBus", return_value=event_bus_mock): |
| 349 | + bot = Device(device_info, authenticator) |
| 350 | + mqtt_client = Mock(spec=MqttClient) |
| 351 | + unsubscribe_mock = Mock(spec=Callable[[], None]) |
| 352 | + mqtt_client.subscribe.return_value = unsubscribe_mock |
| 353 | + await bot.initialize(mqtt_client) |
| 354 | + |
| 355 | + bot.events.notify(pos_event) |
| 356 | + await block_till_done(event_bus._tasks) |
| 357 | + |
| 358 | + if expected_call: |
| 359 | + event_bus_mock.request_refresh.assert_called_once_with(StateEvent) |
| 360 | + else: |
| 361 | + event_bus_mock.request_refresh.assert_not_called() |
| 362 | + |
| 363 | + # teardown bot |
| 364 | + await bot.teardown() |
0 commit comments