def no_auth_websocket_client(hass, loop, test_client):
    """Websocket connection that requires authentication."""
    websocket_app = mock_http_component_app(hass, API_PASSWORD)
    wapi.WebsocketAPIView().register(websocket_app.router)

    client = loop.run_until_complete(test_client(websocket_app))
    ws = loop.run_until_complete(client.ws_connect(wapi.URL))

    auth_ok = loop.run_until_complete(ws.receive_json())
    assert auth_ok['type'] == wapi.TYPE_AUTH_REQUIRED

    yield ws

    if not ws.closed:
        loop.run_until_complete(ws.close())
def websocket_client(loop, hass, test_client):
    """Websocket client fixture connected to websocket server."""
    websocket_app = mock_http_component_app(hass)
    wapi.WebsocketAPIView().register(websocket_app.router)

    client = loop.run_until_complete(test_client(websocket_app))
    ws = loop.run_until_complete(client.ws_connect(wapi.URL))

    auth_ok = loop.run_until_complete(ws.receive_json())
    assert auth_ok['type'] == wapi.TYPE_AUTH_OK

    yield ws

    if not ws.closed:
        loop.run_until_complete(ws.close())