@@ -130,6 +130,19 @@ def test_websocket_get_rendered_template(websocket_client: WebsocketClient) -> N
130130 }
131131
132132
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+
133146def test_check_api_config (cached_client : Client ) -> None :
134147 """Tests the `POST /api/config/core/check_config` endpoint."""
135148 assert cached_client .check_api_config ()
@@ -158,6 +171,14 @@ def test_websocket_get_entities(websocket_client: WebsocketClient) -> None:
158171 assert "sun" in entities
159172
160173
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+
161182def test_get_domains (cached_client : Client ) -> None :
162183 """Tests the `GET /api/services` endpoint."""
163184 domains = cached_client .get_domains ()
@@ -176,6 +197,14 @@ def test_websocket_get_domains(websocket_client: WebsocketClient) -> None:
176197 assert "homeassistant" in domains
177198
178199
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+
179208def test_get_domain (cached_client : Client ) -> None :
180209 """Tests the `GET /api/services` endpoint."""
181210 domain = cached_client .get_domain ("homeassistant" )
@@ -197,6 +226,15 @@ def test_websocket_get_domain(websocket_client: WebsocketClient) -> None:
197226 assert domain .services
198227
199228
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+
200238def test_trigger_service (cached_client : Client ) -> None :
201239 """Tests the `POST /api/services/<domain>/<service>` endpoint."""
202240 notify = cached_client .get_domain ("notify" )
@@ -231,6 +269,19 @@ def test_websocket_trigger_service(websocket_client: WebsocketClient) -> None:
231269 assert resp is None
232270
233271
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+
234285def test_trigger_service_with_response (cached_client : Client ) -> None :
235286 """Tests the `POST /api/services/<domain>/<service>?return_response` endpoint."""
236287 weather = cached_client .get_domain ("weather" )
@@ -267,6 +318,20 @@ def test_websocket_trigger_service_with_response(
267318 assert data is not None
268319
269320
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+
270335def test_get_states (cached_client : Client ) -> None :
271336 """Tests the `GET /api/states` endpoint."""
272337 states = cached_client .get_states ()
@@ -288,6 +353,15 @@ def test_websocket_get_states(websocket_client: WebsocketClient) -> None:
288353 assert isinstance (state , State )
289354
290355
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+
291365def test_get_state (cached_client : Client ) -> None :
292366 """Tests the `GET /api/states/<entity_id>` endpoint."""
293367 state = cached_client .get_state (entity_id = "sun.sun" )
0 commit comments