2
2
3
3
from unittest .mock import AsyncMock , patch
4
4
5
+ from freezegun .api import FrozenDateTimeFactory
5
6
from syrupy import SnapshotAssertion
6
7
7
8
from homeassistant .components .wmspro .const import DOMAIN
9
+ from homeassistant .components .wmspro .cover import SCAN_INTERVAL
8
10
from homeassistant .const import (
9
11
ATTR_ENTITY_ID ,
10
12
SERVICE_CLOSE_COVER ,
11
13
SERVICE_OPEN_COVER ,
12
14
SERVICE_SET_COVER_POSITION ,
13
15
SERVICE_STOP_COVER ,
16
+ STATE_CLOSED ,
17
+ STATE_OPEN ,
14
18
Platform ,
15
19
)
16
20
from homeassistant .core import HomeAssistant
17
21
from homeassistant .helpers import device_registry as dr
18
- from homeassistant .setup import async_setup_component
19
22
20
23
from . import setup_config_entry
21
24
22
- from tests .common import MockConfigEntry
25
+ from tests .common import MockConfigEntry , async_fire_time_changed
23
26
24
27
25
28
async def test_cover_device (
@@ -48,6 +51,7 @@ async def test_cover_update(
48
51
mock_hub_ping : AsyncMock ,
49
52
mock_hub_configuration_prod : AsyncMock ,
50
53
mock_hub_status_prod_awning : AsyncMock ,
54
+ freezer : FrozenDateTimeFactory ,
51
55
snapshot : SnapshotAssertion ,
52
56
) -> None :
53
57
"""Test that a cover entity is created and updated correctly."""
@@ -60,15 +64,12 @@ async def test_cover_update(
60
64
assert entity is not None
61
65
assert entity == snapshot
62
66
63
- await async_setup_component (hass , "homeassistant" , {})
64
- await hass .services .async_call (
65
- "homeassistant" ,
66
- "update_entity" ,
67
- {ATTR_ENTITY_ID : entity .entity_id },
68
- blocking = True ,
69
- )
67
+ # Move time to next update
68
+ freezer .tick (SCAN_INTERVAL )
69
+ async_fire_time_changed (hass )
70
+ await hass .async_block_till_done (wait_background_tasks = True )
70
71
71
- assert len (mock_hub_status_prod_awning .mock_calls ) = = 3
72
+ assert len (mock_hub_status_prod_awning .mock_calls ) > = 3
72
73
73
74
74
75
async def test_cover_open_and_close (
@@ -87,7 +88,7 @@ async def test_cover_open_and_close(
87
88
88
89
entity = hass .states .get ("cover.markise" )
89
90
assert entity is not None
90
- assert entity .state == "closed"
91
+ assert entity .state == STATE_CLOSED
91
92
assert entity .attributes ["current_position" ] == 0
92
93
93
94
with patch (
@@ -105,7 +106,7 @@ async def test_cover_open_and_close(
105
106
106
107
entity = hass .states .get ("cover.markise" )
107
108
assert entity is not None
108
- assert entity .state == "open"
109
+ assert entity .state == STATE_OPEN
109
110
assert entity .attributes ["current_position" ] == 100
110
111
assert len (mock_hub_status_prod_awning .mock_calls ) == before
111
112
@@ -124,7 +125,7 @@ async def test_cover_open_and_close(
124
125
125
126
entity = hass .states .get ("cover.markise" )
126
127
assert entity is not None
127
- assert entity .state == "closed"
128
+ assert entity .state == STATE_CLOSED
128
129
assert entity .attributes ["current_position" ] == 0
129
130
assert len (mock_hub_status_prod_awning .mock_calls ) == before
130
131
@@ -145,7 +146,7 @@ async def test_cover_open_to_pos(
145
146
146
147
entity = hass .states .get ("cover.markise" )
147
148
assert entity is not None
148
- assert entity .state == "closed"
149
+ assert entity .state == STATE_CLOSED
149
150
assert entity .attributes ["current_position" ] == 0
150
151
151
152
with patch (
@@ -163,7 +164,7 @@ async def test_cover_open_to_pos(
163
164
164
165
entity = hass .states .get ("cover.markise" )
165
166
assert entity is not None
166
- assert entity .state == "open"
167
+ assert entity .state == STATE_OPEN
167
168
assert entity .attributes ["current_position" ] == 50
168
169
assert len (mock_hub_status_prod_awning .mock_calls ) == before
169
170
@@ -184,7 +185,7 @@ async def test_cover_open_and_stop(
184
185
185
186
entity = hass .states .get ("cover.markise" )
186
187
assert entity is not None
187
- assert entity .state == "closed"
188
+ assert entity .state == STATE_CLOSED
188
189
assert entity .attributes ["current_position" ] == 0
189
190
190
191
with patch (
@@ -202,7 +203,7 @@ async def test_cover_open_and_stop(
202
203
203
204
entity = hass .states .get ("cover.markise" )
204
205
assert entity is not None
205
- assert entity .state == "open"
206
+ assert entity .state == STATE_OPEN
206
207
assert entity .attributes ["current_position" ] == 80
207
208
assert len (mock_hub_status_prod_awning .mock_calls ) == before
208
209
@@ -221,6 +222,6 @@ async def test_cover_open_and_stop(
221
222
222
223
entity = hass .states .get ("cover.markise" )
223
224
assert entity is not None
224
- assert entity .state == "open"
225
+ assert entity .state == STATE_OPEN
225
226
assert entity .attributes ["current_position" ] == 80
226
227
assert len (mock_hub_status_prod_awning .mock_calls ) == before
0 commit comments