1
1
"""Test for Home Connect coordinator."""
2
2
3
3
from collections .abc import Awaitable , Callable
4
+ from datetime import timedelta
4
5
from typing import Any
5
6
from unittest .mock import AsyncMock , MagicMock , patch
6
7
12
13
EventKey ,
13
14
EventMessage ,
14
15
EventType ,
15
- Status ,
16
- StatusKey ,
17
16
)
18
17
from aiohomeconnect .model .error import (
19
18
EventStreamInterruptedError ,
24
23
import pytest
25
24
26
25
from homeassistant .components .home_connect .const import (
27
- BSH_DOOR_STATE_LOCKED ,
28
26
BSH_DOOR_STATE_OPEN ,
29
27
BSH_EVENT_PRESENT_STATE_PRESENT ,
30
28
BSH_POWER_OFF ,
38
36
callback ,
39
37
)
40
38
from homeassistant .helpers import entity_registry as er
39
+ from homeassistant .util import dt as dt_util
41
40
42
- from tests .common import MockConfigEntry
41
+ from tests .common import MockConfigEntry , async_fire_time_changed
43
42
44
43
45
44
@pytest .fixture
@@ -286,9 +285,6 @@ async def test_event_listener_error(
286
285
(
287
286
"entity_id" ,
288
287
"initial_state" ,
289
- "status_key" ,
290
- "status_value" ,
291
- "after_refresh_expected_state" ,
292
288
"event_key" ,
293
289
"event_value" ,
294
290
"after_event_expected_state" ,
@@ -297,24 +293,15 @@ async def test_event_listener_error(
297
293
(
298
294
"sensor.washer_door" ,
299
295
"closed" ,
300
- StatusKey .BSH_COMMON_DOOR_STATE ,
301
- BSH_DOOR_STATE_LOCKED ,
302
- "locked" ,
303
296
EventKey .BSH_COMMON_STATUS_DOOR_STATE ,
304
297
BSH_DOOR_STATE_OPEN ,
305
298
"open" ,
306
299
),
307
300
],
308
301
)
309
- @patch (
310
- "homeassistant.components.home_connect.coordinator.EVENT_STREAM_RECONNECT_DELAY" , 0
311
- )
312
302
async def test_event_listener_resilience (
313
303
entity_id : str ,
314
304
initial_state : str ,
315
- status_key : StatusKey ,
316
- status_value : Any ,
317
- after_refresh_expected_state : str ,
318
305
event_key : EventKey ,
319
306
event_value : Any ,
320
307
after_event_expected_state : str ,
@@ -345,16 +332,13 @@ async def stream_exception():
345
332
346
333
assert hass .states .is_state (entity_id , initial_state )
347
334
348
- client .get_status .return_value = ArrayOfStatus (
349
- [Status (key = status_key , raw_key = status_key .value , value = status_value )],
350
- )
351
335
await hass .async_block_till_done ()
352
336
future .set_exception (exception )
353
337
await hass .async_block_till_done ()
338
+ async_fire_time_changed (hass , dt_util .utcnow () + timedelta (seconds = 30 ))
354
339
await hass .async_block_till_done ()
355
340
356
341
assert client .stream_all_events .call_count == 2
357
- assert hass .states .is_state (entity_id , after_refresh_expected_state )
358
342
359
343
await client .add_events (
360
344
[
0 commit comments