@@ -130,6 +130,19 @@ def test_websocket_get_rendered_template(websocket_client: WebsocketClient) -> N
130
130
}
131
131
132
132
133
+ async def test_async_websocket_get_rendered_template (
134
+ async_websocket_client : WebsocketClient
135
+ ) -> None :
136
+ """Tests the `"type": "render_template"` websocket command."""
137
+ rendered_template = await async_websocket_client .async_get_rendered_template (
138
+ 'The sun is {{ states("sun.sun").replace("_", " the ") }}.'
139
+ )
140
+ assert rendered_template in {
141
+ "The sun is above the horizon." ,
142
+ "The sun is below the horizon." ,
143
+ }
144
+
145
+
133
146
def test_check_api_config (cached_client : Client ) -> None :
134
147
"""Tests the `POST /api/config/core/check_config` endpoint."""
135
148
assert cached_client .check_api_config ()
@@ -158,6 +171,14 @@ def test_websocket_get_entities(websocket_client: WebsocketClient) -> None:
158
171
assert "sun" in entities
159
172
160
173
174
+ async def test_async_websocket_get_entities (
175
+ async_websocket_client : WebsocketClient
176
+ ) -> None :
177
+ """Tests the `"type": "get_entities"` websocket command."""
178
+ entities = await async_websocket_client .async_get_entities ()
179
+ assert "sun" in entities
180
+
181
+
161
182
def test_get_domains (cached_client : Client ) -> None :
162
183
"""Tests the `GET /api/services` endpoint."""
163
184
domains = cached_client .get_domains ()
@@ -176,6 +197,14 @@ def test_websocket_get_domains(websocket_client: WebsocketClient) -> None:
176
197
assert "homeassistant" in domains
177
198
178
199
200
+ async def test_async_websocket_get_domains (
201
+ async_websocket_client : WebsocketClient
202
+ ) -> None :
203
+ """Tests the `"type": "get_domains"` websocket command."""
204
+ domains = await async_websocket_client .async_get_domains ()
205
+ assert "homeassistant" in domains
206
+
207
+
179
208
def test_get_domain (cached_client : Client ) -> None :
180
209
"""Tests the `GET /api/services` endpoint."""
181
210
domain = cached_client .get_domain ("homeassistant" )
@@ -197,6 +226,15 @@ def test_websocket_get_domain(websocket_client: WebsocketClient) -> None:
197
226
assert domain .services
198
227
199
228
229
+ async def test_async_websocket_get_domain (
230
+ async_websocket_client : WebsocketClient
231
+ ) -> None :
232
+ """Tests the `"type": "get_domain"` websocket command."""
233
+ domain = await async_websocket_client .async_get_domain ("homeassistant" )
234
+ assert domain is not None
235
+ assert domain .services
236
+
237
+
200
238
def test_trigger_service (cached_client : Client ) -> None :
201
239
"""Tests the `POST /api/services/<domain>/<service>` endpoint."""
202
240
notify = cached_client .get_domain ("notify" )
@@ -231,6 +269,19 @@ def test_websocket_trigger_service(websocket_client: WebsocketClient) -> None:
231
269
assert resp is None
232
270
233
271
272
+ async def test_async_websocket_trigger_service (
273
+ async_websocket_client : WebsocketClient
274
+ ) -> None :
275
+ """Tests the `"type": "trigger_service"` websocket command."""
276
+ notify = await async_websocket_client .async_get_domain ("notify" )
277
+ assert notify is not None
278
+ resp = await notify .persistent_notification (
279
+ message = "Your API Test Suite just said hello!" , title = "Test Suite Notifcation"
280
+ )
281
+ # Websocket API doesnt return changed states so we check for None
282
+ assert resp is None
283
+
284
+
234
285
def test_trigger_service_with_response (cached_client : Client ) -> None :
235
286
"""Tests the `POST /api/services/<domain>/<service>?return_response` endpoint."""
236
287
weather = cached_client .get_domain ("weather" )
@@ -267,6 +318,20 @@ def test_websocket_trigger_service_with_response(
267
318
assert data is not None
268
319
269
320
321
+ async def test_async_websocket_trigger_service_with_response (
322
+ async_websocket_client : WebsocketClient
323
+ ) -> None :
324
+ """Tests the `"type": "trigger_service_with_response"` websocket command."""
325
+ weather = await async_websocket_client .async_get_domain ("weather" )
326
+ assert weather is not None
327
+ data = weather .get_forecasts (
328
+ entity_id = "weather.forecast_home" ,
329
+ type = "hourly" ,
330
+ )
331
+ # Websocket API doesnt return changed states so we check data is not None because we expect a response
332
+ assert data is not None
333
+
334
+
270
335
def test_get_states (cached_client : Client ) -> None :
271
336
"""Tests the `GET /api/states` endpoint."""
272
337
states = cached_client .get_states ()
@@ -288,6 +353,15 @@ def test_websocket_get_states(websocket_client: WebsocketClient) -> None:
288
353
assert isinstance (state , State )
289
354
290
355
356
+ async def test_async_websocket_get_states (
357
+ async_websocket_client : WebsocketClient
358
+ ) -> None :
359
+ """Tests the `"type": "get_states"` websocket command."""
360
+ states = await async_websocket_client .async_get_states ()
361
+ for state in states :
362
+ assert isinstance (state , State )
363
+
364
+
291
365
def test_get_state (cached_client : Client ) -> None :
292
366
"""Tests the `GET /api/states/<entity_id>` endpoint."""
293
367
state = cached_client .get_state (entity_id = "sun.sun" )
0 commit comments