1 """Assist satellite connection test."""
4 from pathlib
import Path
6 from aiohttp
import web
10 from .const
import CONNECTION_TEST_DATA
12 _LOGGER = logging.getLogger(__name__)
14 CONNECTION_TEST_CONTENT_TYPE =
"audio/mpeg"
15 CONNECTION_TEST_FILENAME =
"connection_test.mp3"
16 CONNECTION_TEST_URL_BASE =
"/api/assist_satellite/connection_test"
20 """View to serve an audio sample for connection test."""
23 url = f
"{CONNECTION_TEST_URL_BASE}/{{connection_id}}"
24 name =
"api:assist_satellite_connection_test"
26 async
def get(self, request: web.Request, connection_id: str) -> web.Response:
27 """Start a get request."""
28 _LOGGER.debug(
"Request for connection test with id %s", connection_id)
30 hass = request.app[KEY_HASS]
31 connection_test_data = hass.data[CONNECTION_TEST_DATA]
33 connection_test_event = connection_test_data.pop(connection_id,
None)
35 if connection_test_event
is None:
36 return web.Response(status=404)
38 connection_test_event.set()
40 audio_path = Path(__file__).parent / CONNECTION_TEST_FILENAME
41 audio_data = await hass.async_add_executor_job(audio_path.read_bytes)
43 return web.Response(body=audio_data, content_type=CONNECTION_TEST_CONTENT_TYPE)
web.Response get(self, web.Request request, str connection_id)